WPF窗口所有者属性问题

时间:2017-02-06 13:41:04

标签: wpf exception owner

我有一个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”。

你有什么建议吗?提前谢谢。

1 个答案:

答案 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();