我有一个WPF MainWindow
,我可以打开第二个,如下所示,以这篇文章为例:
var win = new CalibrationWindow(){Owner = this};
win.ShowDialog();
很少发生以下运行时异常" cannot set owner property to a window that has not been shown previously
"。
你有什么建议吗?提前谢谢。
处理窗口的 StateChanged 或 Activated 事件,并在此事件处理程序中设置 Owner 属性,如下所示:
在父构造函数中设置窗口的所有者时遇到问题
var win = CalibrationWindow();
this.Activated += (s, e) => { win.Owner = this; };
win.ShowDialog();