为什么向Activated添加处理程序会阻止窗口出现?

时间:2016-06-27 15:56:07

标签: c# wpf windows

当我的应用程序的主窗口打开时,我想要另一个窗口作为伴侣打开它。所以我为Activated事件添加了一个处理程序:

public MainWindow()
{
    InitializeComponent();

    // ...

    Activated += OnFirstActivation;

    // ...
}

private void OnFirstActivation(object sender, EventArgs eventArgs)
{
    _otherWindow.Owner = this;
    _otherWindow.Show();
    Activated -= OnFirstActivation;
}

在进行此更改之前,主窗口会弹出并在激活时关注。有了这个改变,当主窗口被激活时,两个窗口都不会这样做。为什么不呢?

0 个答案:

没有答案