added samples
[windows-sources.git] / sdk / samples / WPFSamples / CodeOnlyWindowsApplicationSample / csharp / mainwindow.cs
blob357748fb04a73a0a43a30a6583ffa0f38547205c
1 using System;
2 using System.Windows;
3 using System.Windows.Controls;
5 namespace CodeOnlyWindowsApplicationSample {
7 /// <summary>
8 /// MainWindow derives from Window to inherit the ability to show
9 /// a window. Developers who derive from Window need to define both
10 /// appearance and behavior in code. Appearance is set by filling the
11 /// Window.Content property, while behavior is created by handling events,
12 /// overriding methods, setting properties, and adding further custom
13 /// behavior code.
14 ///
15 /// NOTE: Since MainWindow is code-only (no markup) there is no need to
16 /// call the InitializeComponent method eg:
17 ///
18 /// public partial class MainWindow : Window {
19 /// public MainWindow() {
20 /// this.InitializeComponent();
21 /// }
22 /// }
23 ///
24 /// InitializeComponent is a method that is generated by the
25 /// compiler when markup exists to apply the MainWindow XAML to
26 /// the actual MainWindow instance, eg to register event handlers.
27 /// If XAML were used, this class would also need to be a partial
28 /// class, to merge with the partial class definition that implements
29 /// the InitializeComponent, method that's generated by the compiler.
30 /// </summary>
31 public class MainWindow : Window {
33 protected override void OnInitialized(EventArgs e) {
34 base.OnInitialized(e);
36 // Create appearance
37 Button closeButton = new Button();
38 closeButton.Content = "Close";
39 this.Content = closeButton;
41 // Define behavior
42 closeButton.Click += delegate {
43 this.Close();