3 using System
.Windows
.Controls
;
5 namespace CodeOnlyWindowsApplicationSample
{
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
15 /// NOTE: Since MainWindow is code-only (no markup) there is no need to
16 /// call the InitializeComponent method eg:
18 /// public partial class MainWindow : Window {
19 /// public MainWindow() {
20 /// this.InitializeComponent();
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.
31 public class MainWindow
: Window
{
33 protected override void OnInitialized(EventArgs e
) {
34 base.OnInitialized(e
);
37 Button closeButton
= new Button();
38 closeButton
.Content
= "Close";
39 this.Content
= closeButton
;
42 closeButton
.Click
+= delegate {