主窗口前显示登录窗口 [英] show Login window before main window
本文介绍了主窗口前显示登录窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的WPF应用程序,我想在sturtup显示登录表单,如果用户输入有效的用户名和密码,窗口1将显示。
I用户的代码在我的app.xmal:
in my wpf application,i want to show login form at sturtup and if user enter a valid 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">
和这个代码app.xmal.cs:
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 closed!
推荐答案
您应该设置 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>
这篇关于主窗口前显示登录窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文