【问题标题】:How to open a dialog center-screen or center-owner?如何打开对话中心屏幕或中心所有者?
【发布时间】:2013-02-06 08:34:37
【问题描述】:

我有一个 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。然而,窗户并没有在主人的中心打开。我试过CenterScreeen,但也没有用。

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

【问题讨论】:

    标签: c# wpf mvvm dialog


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      • 2022-07-03
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 2017-11-21
      • 1970-01-01
      相关资源
      最近更新 更多