예제 #1
0
		static void Main()
		{
			//The WinForms Application will be the main UI loop
			System.Windows.Forms.Application.EnableVisualStyles();
			System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
			SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());

			//it's more awkward to have WinForms run the show; in certain cirumstances, if you don't change the WPF Application shutdown mode,
			//the application will be destroyed when that window is closed (because of the default "OnLastWindowClose")
			//then when you open a second WPF window...boom
			System.Windows.Application wpfApplication = new System.Windows.Application
			{
				//comment out this line to test, then click the button on the form to show another WPF window
				ShutdownMode = ShutdownMode.OnExplicitShutdown
			};
			
			WinFormsProgramAddWpf p = new WinFormsProgramAddWpf();
			p.ExitRequested += (sender, e) =>
			{
				System.Windows.Forms.Application.ExitThread();
			};

			Task programStart = p.StartAsync();
			HandleExceptions(programStart);


			System.Windows.Forms.Application.Run();
			//now the wpf application can also shut down
			wpfApplication.Shutdown();
		}
예제 #2
0
        static void Main()
        {
            //The WinForms Application will be the main UI loop
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
            SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());

            //it's more awkward to have WinForms run the show; in certain cirumstances, if you don't change the WPF Application shutdown mode,
            //the application will be destroyed when that window is closed (because of the default "OnLastWindowClose")
            //then when you open a second WPF window...boom
            System.Windows.Application wpfApplication = new System.Windows.Application
            {
                //comment out this line to test, then click the button on the form to show another WPF window
                ShutdownMode = ShutdownMode.OnExplicitShutdown
            };

            WinFormsProgramAddWpf p = new WinFormsProgramAddWpf();

            p.ExitRequested += (sender, e) =>
            {
                System.Windows.Forms.Application.ExitThread();
            };

            Task programStart = p.StartAsync();

            HandleExceptions(programStart);


            System.Windows.Forms.Application.Run();
            //now the wpf application can also shut down
            wpfApplication.Shutdown();
        }