ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CodeGo.net> ContentDialog不对齐以UWP为中心

2019-11-18 22:06:14  阅读:209  来源: 互联网

标签:windows-10-universal windows-10 win-universal-app c


据我所知,ContentDialog的默认行为应该是使其居中于PC并在移动设备上居于顶部,但就我而言,即使在PC上它也居于顶部,我也不知道发生了什么.

我使用后台代码创建它,这是我正在使用的代码的片段:

// Creates the password box
var passwordBox = new PasswordBox {IsPasswordRevealButtonEnabled = true, Margin = new Thickness(5)};            

// Creates the StackPanel with the content
var contentPanel = new StackPanel();
contentPanel.Children.Add(new TextBlock
{
    Text = "Insert your password to access the application",
    Margin = new Thickness(5),
    TextWrapping = TextWrapping.WrapWholeWords
});
contentPanel.Children.Add(passwordBox);       

// Creates the password dialog
_passwordDialog = new ContentDialog
{
    PrimaryButtonText = "accept",
    IsPrimaryButtonEnabled = false,
    SecondaryButtonText = "exit",
    Title = "Authentication",
    Content = contentPanel
};

// Report that the dialog has been opened to avoid overlapping
_passwordDialog.Opened += (s, e) =>
{
    // HACK - opacity set to 0 to avoid seeing behind dialog
    Window.Current.Content.Opacity = 0;
    _canShowPasswordDialog = false;
};
// Report that the dialog has been closed to enable it again
_passwordDialog.Closed += (s, e) =>
{
    // HACK - opacity set to 1 to reset the window to original options
    Window.Current.Content.Opacity = 1;
    _canShowPasswordDialog = true;
};

// Clear inserted password for next logins
_passwordDialog.PrimaryButtonClick += (s, e) =>
{
    // ... login ...
};

// Close the app if the user doesn't insert the password
_passwordDialog.SecondaryButtonClick += (s, e) => { BootStrapper.Current.Exit(); };

// Set the binding to enable/disable the accept button 

_passwordDialog.SetBinding(ContentDialog.IsPrimaryButtonEnabledProperty, new Binding
{
    Source = passwordBox,
    Path = new PropertyPath("Password"),
    Mode = BindingMode.OneWay,
    Converter = new PasswordValidatorConverter()
});

我已经尝试过使用VerticalAlignment和FullSizeDesired,但没有得到预期的结果.

我怎样才能解决这个问题?

解决方法:

ContentDialog就像Popup控件,当它显示在页面上时,PopupRoot会保存它.但是与Popup控件不同,ContentDialog的放置位置是在后面的代码中编写的,并且此属性不会暴露给我们,因此无法更改.

From what I know, ContentDialog’s default behavior should be to have it centered on PC.

ContentDialog并不总是以PC为中心.我根据您发布的代码测试ContentDialog.当页面高度小于640时,ContentDialog会对齐到页面顶部.当页面高度等于640或大于640时,它将位于页面的中心.

enter image description here

从上图可以看到,放置ContentDialog的位置是由Page的高度触发的.

标签:windows-10-universal,windows-10,win-universal-app,c
来源: https://codeday.me/bug/20191118/2031327.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有