2016-05-05 69 views
0

アプリケーションの起動時に以下のメソッドが実行され、まずメンテナンス画面が表示されます。メソッドの実行後、私は自分のログイン画面を表示したい。しかし、ログイン画面は開きません。メンテナンス画面を表示するコードをコメントアウトするとうまくいきます。show()コマンドでウィンドウが開かないWpf

private void Application_Startup(object sender, StartupEventArgs e) 
    { 

     ILocalDbDataService _locDataService =new LocalDbDataService(); 

      Maintenance mWin = new Maintenance(); 
      mWin.Show(); 

      MaintenanceViewModel maintenanceViewModel = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<MaintenanceViewModel>(); 
      maintenanceViewModel.RunMaintenance(); 
      Login lWin = new Login();     
      lWin.Show();//This windows doesn't open 
} 

public class MaintenanceViewModel : ViewModelBase 
{ 

    private readonly ILocalDbDataService _localDbDataService; 

    public MaintenanceViewModel(ILocalDbDataService localDbDataService) 
    { 
     _localDbDataService = localDbDataService; 

    } 

    public void RunMaintenance() 
    { 
     bool result= _localDbDataService.RunTransArchiveMaintenance(); 
     MessengerInstance.Send(new NotificationMessage("CloseMaintenance")); 
    } 
} 
public partial class Maintenance : Window 
{ 
    public Maintenance() 
    { 
     InitializeComponent(); 

     Messenger.Default.Register<NotificationMessage>(this, msg => 
     { 
      if (msg.Notification == "CloseMaintenance") 
      { 
       this.Close(); 
      } 
     }); 
    } 
} 

答えて

0

メンテナンスウィンドウのコンストラクタで、ログインウィンドウクラスの新しいインスタンスを作成し、Show()を呼び出します。

public Maintenance(){ 
Login login=new Login(); 
login.Show(); 
} 
0

これをメインウィンドウに配置してください。

<ContentControl x:Name="SomeName" 
       Grid.Row="1" 
       HorizontalAlignment="Stretch" 
       VerticalAlignment="Stretch" 
       Content="{Binding CurrentScreen}" /> 

を変更したいときCurrentScreenのUserControlプロパティを設定し

CurrentScreen = new MaintenancePage(); 
CurrentScreen = new LogInPage(); // LoginPage.xaml is your login view. 
関連する問題