Question

I have a problem regarding StartUp Url in WPF. I have a LoginView.xaml and MainWindow.xaml. I want at first to open LoginView after that automatically to be opened MainWindow.

App.xaml

<Application x:Class="XXX.App"
    xmlns="....."            
    Startup="App_Startup" 
    >

App.xaml.cs

/

// <summary>
    /// Called when the application starts.
    /// </summary>
    private void App_Startup(object sender, StartupEventArgs e)
    {
        LoginView frmLogin = new LoginView();
        bool? resultScreen = frmLogin.ShowDialog();
        if (frmLogin.ShowDialog())
        {
            Uri uri = new Uri("pack:/MainWindow.xaml", UriKind.RelativeOrAbsolute);
            Application.Current.StartupUri = uri;
        }
        else
        {
            Application.Current.Shutdown();
        }
    }

LoginView window opened normally, after that nothing happened, and application is closed.

I tried another approach, but I've got the same result.

App.xaml

<Application x:Class="XXX.App"
    xmlns="....."            
    Startup="App_Startup" 
    >

App.xaml.cs

/// <summary>
    /// Called when the application starts.
    /// </summary>
    private void App_Startup(object sender, StartupEventArgs e)
    {
        LoginView frmLogin = new LoginView();
        bool? resultScreen = frmLogin.ShowDialog();
        if frmLogin.ShowDialog())
        {
            MainWindow frmMainWindow = new MainWindow();
            frmMainWindow.ShowDialog();
        }
        else
        {
            Application.Current.Shutdown();
        }
    }

Who can tell me, how can I get to the desired result? Thanks in advance.

Was it helpful?

Solution

Again I found the solution of my problem myself :) here is the solution

http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top