gpt4 book ai didi

c# - ContentDialog 未对齐以 UWP 为中心

转载 作者:行者123 更新时间:2023-11-30 16:49:36 46 4
gpt4 key购买 nike

据我所知,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()
});

我已经尝试使用 VerticalAlignmentFullSizeDesired 但我没有得到预期的结果。

我该如何解决这个问题?

最佳答案

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的高度触发的。

关于c# - ContentDialog 未对齐以 UWP 为中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36384062/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com