我有一个WPF MainWindow
我可以在下面打开第二个,以this post为例:
var win = new CalibrationWindow(){Owner = this};
win.ShowDialog();
我很少遇到以下运行时异常“cannot set owner property to a window that has not been shown previously
”。
你有什么建议吗?提前谢谢。
答案 0 :(得分:0)
处理窗口的StateChanged或Activated事件,并按照此处的建议在此事件处理程序中设置Owner属性:
Having Trouble Setting Window's Owner in Parent's Constructor
var win = CalibrationWindow();
this.Activated += (s, e) => { win.Owner = this; };
win.ShowDialog();