Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show Login window before main window

Tags:

c#

wpf

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

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!

like image 213
ozzy_mra Avatar asked Jul 28 '13 15:07

ozzy_mra


1 Answers

You should set Application.ShutdownMode to OnExplicitShutdown (msdn).

Example:

<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>
like image 165
kmatyaszek Avatar answered Oct 31 '22 15:10

kmatyaszek