static void Main() { AppNoStartupUri app = new AppNoStartupUri { ShutdownMode = ShutdownMode.OnExplicitShutdown }; app.InitializeComponent(); Program3 p = new Program3(); p.ExitRequested += (sender, e) => { app.Shutdown(); }; p.Start(); app.Run(); }