WPF Application.
Window1 can open WindowA.Show(), WindowB.Show(), WindowC.Show()
When we close Window1 we want to close all open windows as well (A, B and C).
On Window1_Closing event we call
WindowA.Close();
WindowB.Close();
WindowC.Close();
On window closing of any of these Cancel = true can be called and the WindowA (or B or C) won't close.
Then we don't want to close Window1 (the parent).
How to know in Window1_Closing if any of the child windows was cancelled (not closed)?
Window.Closed event is fired after the window is closed. Either move your logic to eventhandler of Closed event, or use the event to send some flag:
bool isClosed = false;
WindowA.Closed += delegate { isClosed = true; };
WindowA.Close();
if (isClosed) {
}
Application.Current.Windows is collection of currently opened windows:
WindowA.Close();
bool isClosed = !Application.Current.Windows.OfType<Window>().Contains(WindowA);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With