1
using System
.ComponentModel
; // CancelEventArgs
2 using System
.Windows
; // Window, RoutedEventArgs
4 namespace WindowCloseHideSample
6 public partial class MainWindow
: Window
8 // To hide/show a window, rather than reinstantiate a window
9 // each time it needs to be opened, we need to retain the instance
10 // in a class-scoped variable
11 private ChildWindow childWindow
;
15 InitializeComponent();
18 private void showChildWindowButton_Click(object sender
, RoutedEventArgs e
)
20 // Create the window if it's not already created
21 if (this.childWindow
== null) this.childWindow
= new ChildWindow();
24 this.childWindow
.Show();
27 private void Window_Closing(object sender
, CancelEventArgs e
)
29 // Close the child window only when this window closes
30 this.childWindow
.Close();