当我的应用程序的主窗口打开时,我想要另一个窗口作为伴侣打开它。所以我为Activated事件添加了一个处理程序:
public MainWindow()
{
InitializeComponent();
// ...
Activated += OnFirstActivation;
// ...
}
private void OnFirstActivation(object sender, EventArgs eventArgs)
{
_otherWindow.Owner = this;
_otherWindow.Show();
Activated -= OnFirstActivation;
}
在进行此更改之前,主窗口会弹出并在激活时关注。有了这个改变,当主窗口被激活时,两个窗口都不会这样做。为什么不呢?