簡體   English   中英

show()命令不會打開Wpf窗口

[英]The show() command doesn't open the window 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();
            }
        });
    }
}

在“維護”窗口的構造函數中,創建“登錄”窗口類的新實例,然后調用Show()。

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

只需將其放在您的主窗口中即可。

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

要更改時設置CurrentScreen用戶控件屬性

CurrentScreen = new MaintenancePage();
CurrentScreen = new LogInPage(); // LoginPage.xaml is your login view.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM