WPF新窗口关闭监听器

时间:2015-03-12 07:40:00

标签: c# wpf

我的主窗口上有一个DataGrid,一些可点击的视图打开一个新窗口。我想在新窗口关闭时“刷新”DataGrid

1 个答案:

答案 0 :(得分:1)

附加到新窗口的关闭事件。在你的MainWindow你应该有这样的东西:

private void Button_Click(object sender, RoutedEventArgs e)
{
    var secondWindow = new SecondWindow();
    secondWindow.Closing += (s, args) => this.Refresh();
    secondWindow.Show();
}
但是,在某些情况下,显示阻塞模式对话框是可行的。在那种情况下:

private void Button_Click(object sender, RoutedEventArgs e)
{
    var secondWindow= new SecondWindow();
    secondWindow.ShowDialog(); //this will wait until window is closed
    this.Refresh();
}