Wpf检测窗口何时从不同的窗口关闭

本文关键字:窗口 检测 何时 Wpf | 更新日期: 2023-09-27 18:03:28

   private void newmail_Click(object sender, RoutedEventArgs e)
    {
        Nieuweemail _nieuweEmail = new Nieuweemail(_username);
        _nieuweEmail.Show();
    }

当这个窗口关闭时,我想在主窗口中调用一个函数来执行。

        _nieuweEmail.Closed += setContent();

如果我能在将要关闭的窗口中调用它,我就可以这样做。但事实并非如此。我该如何检测呢?

Wpf检测窗口何时从不同的窗口关闭

假设setContentnewmail_Click都是主窗口中的方法…

private void newmail_Click(object sender, RoutedEventArgs e)
{
    Nieuweemail _nieuweEmail = new Nieuweemail(_username);
    _nieuweEmail.Closed += SetContentHandler;
    _nieuweEmail.Show();
}
private void SetContentHandler(object sender, EventArgs e)
{
    setContent();
}