CodeGo.net> ContentDialog不对齐以UWP为中心
作者:互联网
据我所知,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时,它将位于页面的中心.
从上图可以看到,放置ContentDialog的位置是由Page的高度触发的.
标签:windows-10-universal,windows-10,win-universal-app,c 来源: https://codeday.me/bug/20191118/2031327.html