using System; using System.Windows; using System.Windows.Controls; public class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); MainWindow window = new MainWindow(); window.Show(); } [STAThread] public static void Main() { App app = new App(); app.Run(); } } public class MainWindow : Window { protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); Button closeButton = new Button(); closeButton.Content = "Close"; this.Content = closeButton; closeButton.Click += delegate { this.Close(); }; } }