1、App.xaml中修改ShutdownMode="OnExplicitShutdown"
<Application x:Class="SBCSML2Client.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SBCSML2Client"
ShutdownMode="OnExplicitShutdown" >
<Application.Resources>
<ResourceDictionary>
<FontFamily x:Key="iconfont">
pack://application:,,,/SBCSML2Client;component/Assets/Fonts/#iconfont
</FontFamily><ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/MergeDictionary.xaml"/>
<!--<ResourceDictionary Source="CommandPage/MenuItemButton.xaml"/>-->
<ResourceDictionary Source="Assets/Styles/GlobalStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary></Application.Resources>
</Application>
2、login界面点击登录按钮连接数据库,验证用户密码
void BtnLogin()
{
DBHandle.InitDB();
DBHandle.ConnToDB();if (DBHandle.CheckUser(SysInfo))
{
DBHandle.InitLogging();
LoggingDriver.info("HMI Start!!!");_window.DialogResult = true;
DBHandle.sysInfo = SysInfo;
}
else
{
MessageBox.Show("账号或者密码输入错误,请重新输入!", "消息提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
}
3、 App.xaml.cs中添加代码,其中LoginWindow是登录界面,MainWindow是主界面。
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);if (new LoginWindow().ShowDialog() == true)
{
new MainWindow().ShowDialog();
}Application.Current.Shutdown();
}
}