Another simple question.
I use a window in WPF as a child window, where I prefer the "X" button to hide the window instead of closing it. For this I have:
private void Window_Closing(object sender, CancelEventArgs e) {
this.Hide();
e.Cancel = true;
}
The problem is that when you close the parent window, it never closes and does not save the application.
Is there a clean way to handle this? I was thinking of adding a Kill flag to all of my user controls (windows):
public bool KillMe;
private void Window_Loaded(object sender, RoutedEventArgs e){
KillMe = false;
}
private void Window_Closing(object sender, CancelEventArgs e) {
this.Hide();
if (!KillMe) e.Cancel = true;
}
Then in MainWindow_Closing () I need to set all the KillMe flags of the window to true.
Any better way than creating extra flags and forgetting to set them before closing?
Paulg source
share