如何打开对话框中心屏幕或中心所有者

本文关键字:所有者 屏幕 打开对话框 | 更新日期: 2023-09-27 17:58:09

我有一个MVVM应用程序和一个主视图模型。在这个模型中,我使用以下代码打开一个对话框:

dlgViewModel myDlgViewModel = new dlgViewModel();
dlgView myDlgView = new dlgView();
myDlgView.DataContext = myDlgViewModel;
myDlgView.Owner = App.Current.MainWindow;
myDlgView.WindowStartupLocation = WindowStartupLocation.CenterOwner;
myDlgView.ShowDialog();

此外,在dlgView上的XAML中,我将WIndowsStartupLocation设置为CenterOwner。但是,在所有者的中心,该窗口不会打开。我试过CenterScreen,但也不起作用。

如何使用centerOwner或centerScreen选项打开新视图?

如何打开对话框中心屏幕或中心所有者

好吧,第一次在我的对话框WindowsStartUpLocation的axml中设置为中心所有者。

然后,在主视图模型中,我使用以下代码:

dlgViewModel myDlgViewModel = new dlgViewModel();
dlgView myDlgView = new dlgView();
myDlgView.DataContext = miDlgViewModel;
myDlgView.Owner = App.Current.MainWindow;
myDlgView.ShowDialog();