added samples
[windows-sources.git] / sdk / samples / WPFSamples / WindowCloseHideSample / csharp / mainwindow.xaml.cs
blob9e4698c000b94e6f3062eaf0575d3ccae9d06e4f
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;
13 public MainWindow()
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();
23 // Show the window
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();