Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3455294
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:35:49+00:00 2026-05-18T09:35:49+00:00

I am only starting to learn WPF so please bear with me if this

  • 0

I am only starting to learn WPF so please bear with me if this problem is so simple, yet I’m unable to figure out what is really happening.

What I’m trying to accomplish is to show a LoginWindow first then after a successful authentication the MainWindow will be displayed. I did not use the default App.xaml that is automatically created by Visual Studio, instead I created a custom application class. The Login works perfectly fine, but the app.Run(win) is not working, it doesn’t show my MainWindow and the application exits immediately. Is there something I’m missing here? I have a winform application with almost same start up class, and it works perfectly fine. So I don’t know why this approach is not working in WPF.

public class Startup
{
    [STAThread()]
    static void Main()
    {
        Application app = new Application();
        WinLogin login = new WinLogin();
        bool showLogin = true;
        while (showLogin)
        {
            login.ShowDialog();
            if (login.DialogResult.HasValue && login.DialogResult == true)
            {
                MainWindow win = new MainWindow();
                app.Run(win);
                if (!win.LogOff)
                    showLogin = false;
            }
            else
                showLogin = false;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:35:49+00:00Added an answer on May 18, 2026 at 9:35 am

    After you have shown your dialog, try setting

    app.MainWindow = win;
    

    just before calling Application.Run(). I guess your first dialog was automatically set as main window, thus shutting down the application after it was closed.

    Also, move the MainWindow creation directly after your application creation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting to learn ruby and am trying to figure out a way
I'm just starting to learn the C programming language. I've written this simple piece
I only starting to learn about SQL Azure, have spoken to some potential clients,
I'm starting to learn threading and have encountered a problem. I have a scoring
I'm just starting to learn more advanced SQL along with PHP and I'm really
Hello I am only starting to learn php can anyone help. I need to
I'm very new with Haskell, only starting to learn it. I'm using Learn You
I searched link from where one may learn Wordpress not only starting level but
I'm only starting with Android dev, and while the Milestone is a nice device
Windows provides only GetTickCount up to Windows Vista and starting from that OS also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.