App.xamlのStartupUriを消去し、自動起動される画面を除去
・修正前
<Application x:Class="WpfApplication.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication" StartupUri="MainWindow.xaml"> <Application.Resources> </Application.Resources> </Application>
・修正後
<Application x:Class="WpfApplication.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication"> <Application.Resources> </Application.Resources> </Application>
App.xaml.csにOnStartupをオーバーライドし、各画面オブジェクトを生成、Showする。
public partial class App : Application { static MainWindow objMainWindow; static MainWindow objMainWindow2; protected override void OnStartup(StartupEventArgs e) { objMainWindow = new MainWindow(); objMainWindow2 = new MainWindow(); objMainWindow.Show(); objMainWindow2.Show(); } }
全ての画面が閉じられると、プロセスが終了する。