Show main window login window

in my wpf application, I want to show the login form and if the user enters the correct username and password, window1 will be displayed. i user this code in my app.xmal:

<Application x:Class="Acountant.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Startup="Application_Startup"> 

and this code in app.xmal.cs:

  private void Application_Startup(object sender, StartupEventArgs e) { LoginFRM f = new LoginFRM(); if (f.ShowDialog() == true) { var frm = new Window1(); frm.ShowDialog(); } } 

but my application is closed!

+4
source share
1 answer

You must set Application.ShutdownMode to OnExplicitShutdown ( msdn ).

Example:

 <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml" ShutdownMode="OnExplicitShutdown" > </Application> 
+2
source

Source: https://habr.com/ru/post/1493933/


All Articles