wpf 检查打开的窗口是否已关闭
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12106657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Check if opened window has been closed
提问by TheGeekZn
I have a main window, which is the application start up window.
In that window, there is a Repeatercontrol binded to a SQL Database, and a button to open a new window.
我有一个主窗口,它是应用程序启动窗口。在那个窗口中,有一个Repeater绑定到的控件SQL Database和一个用于打开新窗口的按钮。
The new window has a method that inserts data into the SQL Databasethat the first windows' Repeatercontrol reads from.
新窗口有一个方法可以将数据插入到SQL Database第一个窗口Repeater控件读取的数据中。
The repeater has a RepeaterRefresh()method that forces it to rebind to the SQL Database, revealing anything added.
转发器有一种RepeaterRefresh()方法可以强制它重新绑定到SQL Database,显示添加的任何内容。
How would I be able to bind the Close()event of the second window to the RepeaterRefresh()method, so the data is automatically shown on the repeater.
我如何能够将Close()第二个窗口的事件绑定到该RepeaterRefresh()方法,以便数据自动显示在中继器上。
I have read this, thisand this, but I still feel that my question doesn't relate.
回答by Clemens
Why not simply add a handler to the Closingor Closedevent:
为什么不简单地向Closing或Closed事件添加一个处理程序:
private void ShowChildWindow()
{
Window childWindow = new ChildWindow();
childWindow.Closed += ChildWindowClosed;
childWindow.Show();
}
private void ChildWindowClosed(object sender, EventArgs e)
{
((Window)sender).Closed -= ChildWindowClosed;
RepeaterRefresh();
}

