【发布时间】:2012-10-03 22:37:24
【问题描述】:
我的 WPF 窗口很少。
当我想打开一个新窗口时,我会关闭当前窗口,并加载一个新窗口:
ProductMain productMain= new ProductMain();
productMain.Show();
this.Close();
我知道你可以把用户控制放到窗口中。
我可以在主窗口中加载窗口吗?
谢谢。
【问题讨论】:
我的 WPF 窗口很少。
当我想打开一个新窗口时,我会关闭当前窗口,并加载一个新窗口:
ProductMain productMain= new ProductMain();
productMain.Show();
this.Close();
我知道你可以把用户控制放到窗口中。
我可以在主窗口中加载窗口吗?
谢谢。
【问题讨论】:
你可以通过设置 Window 的 owner 属性来做类似的事情。要获取主窗口,请使用:
Application.Current.MainWindow
之后,您可以设置ProductMain窗口的owner:
ProductMain productMain= new ProductMain();
productMain.Owner = Application.Current.MainWindow;
productMain.Show();
【讨论】: