/*
# build
#
/target:winexe
/out:SimpleWPFApp.exe
/r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll"
/r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll"
/r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll"
MyWPF.cs
*/
using System;
using System.Windows;
using System.Windows.Controls;
class MyWPFApp : Application
{
[STAThread]
static void Main()
{
MyWPFApp app = new MyWPFApp();
app.Startup += AppStartUp;
app.Exit += AppExit;
app.Run();
}
static void AppExit(object sender, ExitEventArgs e)
{
MessageBox.Show("App has exited");
}
static void AppStartUp(object sender, StartupEventArgs e)
{
MainWindow wnd = new MainWindow("My better WPF App!", 200, 300);
}
}
class MainWindow : Window
{
Button btnExitApp = new Button();
public MainWindow(string windowTitle, int height, int width)
{
btnExitApp.Click += new RoutedEventHandler(btnExitApp_Clicked);
btnExitApp.Content = "Exit Application";
btnExitApp.Height = 25;
btnExitApp.Width = 100;
this.AddChild(btnExitApp);
this.Title = windowTitle;
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
this.Height = height;
this.Width = width;
this.Show();
}
private void btnExitApp_Clicked(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
}