To set how to display the login window:
In the App.xaml, this sentence
Delete startupuri= "MainWindow.xaml" to Startupuri= "Login/loginwindow.xaml"//Login/loginwindow.xaml is the login window;
Plus shutdownmode= "Onlastwindowclose"
The code is as follows:
Public Partial classLoginwindow:window { PublicLoginwindow () {InitializeComponent (); } Private voidbtnClose_Click (Objectsender, RoutedEventArgs e) {System.Windows.Application.Current.Shutdown (); } Private voidBtnlogin_click (Objectsender, RoutedEventArgs e) { if(user_name. Text! = loginconfig.getsettingstring ("UserName") ||password. Password! = loginconfig.getsettingstring ("Password") {MessageBox.Show ("The user name or password is wrong! "); } Else { (NewMainWindow ()). Show ();//display the main window;Close (); } } }
WPF Displays login success first, show main window after successful validation