全部博文(105)
分类: 嵌入式
2012-04-14 12:29:14
1. Closing all other Windows when closing a main window
Normally in an application your have a main window that does some essential functionality. An example could be your web browser. The browser window is the main window and you may have an extra window which you can manage your bookmarks.
A quick and easy way i found to do this was create an event handler for the “Closing” event for the main window:
Closing="Window_Closing"
In the event handler we do this:
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
The real gem here is the App.Current.Windows collection, which does what it says on the tin and has a collection of all the windows that have been created in your application. An important part of the snippet above is that we make sure to not close the Window that the code belongs to otherwise you get an Exception, trust me i tried it!