在主窗口之前显示登陆窗口

5

在我的WPF应用程序中,我希望在启动时显示登录表单,如果用户输入有效的用户名和密码,则会显示Window1窗口。 我在我的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">

并且在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();
     }
 }

但是我的应用程序关闭了!
1个回答

6

你应该将Application.ShutdownMode设置为OnExplicitShutdown(msdn)。

示例:

<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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接