I have a following method that runs on my application startup where I first show the Maintenance screen. After the method runs I want to show my login screen. But,the login screen doesn't open. It works fine if I comment out the code that shows the maintenance screen.
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();
}
});
}
}
In the Maintenance window's constructor, create a new instance of the Login window class and call Show().
public Maintenance (){
Login login=new Login ();
login.Show();
}
Just place this in your Main window.
<ContentControl x:Name="SomeName"
Grid.Row="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Content="{Binding CurrentScreen}" />
Set the CurrentScreen usercontrol property when you want to change
CurrentScreen = new MaintenancePage();
CurrentScreen = new LogInPage(); // LoginPage.xaml is your login view.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.