修改App.xaml.cs文件的OnStartup代码如下:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
UI_Login login = new UI_Login();
bool? result = login.ShowDialog();
if (result == null ? false : Convert.ToBoolean(result))
{
UI_MainView mv = new UI_MainView();
mv.ShowDialog();
}
Environment.Exit(0);
}
下面这条是关键,在App.xaml里添加属性 ShutdownMode="OnExplicitShutdown"
<Application x:Class="MES.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MES.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
StartupUri="View/Main/M_Login.xaml"
ShutdownMode="OnExplicitShutdown"
mc:Ignorable="d">