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 8679983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:07:59+00:00 2026-06-12T21:07:59+00:00

I have a login window and a main window. Now, I want to close

  • 0

I have a login window and a main window. Now, I want to close the login window after a successful login and my main window should then open. But so far, I am getting both windows opening which is irritating me.

I have tried the code below in the code behind of app.xaml but it closes the whole application…

DataRepository repository = new DataRepository();
ViewModelPassword viewModelPassword = new ViewModelPassword(repository);

passwordDialog passwordDialog = new PasswordDialog();
passwordDialog.DataContext = viewModelPassword;

viewModelPassword.RequestClose += (s, ee) => passwordDialog.Close();
passwordDialog.ShowDialog();

Mainviewmodel viewModel = new Mainviewmodel (repository, viewModelPassword.Login);
MainWindow window = new MainWindow();

window.DataContext = viewModel;
window.Show();

base.OnStartup(e);

After the login command has initiated a successful login, I want to display the main window.

  • 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-06-12T21:08:00+00:00Added an answer on June 12, 2026 at 9:08 pm

    You are showing both Windows before even running the startup code, so on application startup both windows are showing.

    Here’s the code I typically use for this scenario:

    protected override void OnStartup(StartupEventArgs e)
    {
        // Run startup code first
        base.OnStartup(e); 
    
        // Create Login Window and Show it
        var login = new LoginDialog();
        var loginVm = new LoginViewModel();
    
        login.DataContext = loginVm;
        login.ShowDialog();
    
        // If login window didn't return true (login failed), exit application
        if (!login.DialogResult.GetValueOrDefault())
        {
            Environment.Exit(0);
        }
    
        // Providing we have a successful login, start main application window
        var app = new ShellView();
        var context = new ShellViewModel(loginVm.CurrentUser);
        app.DataContext = context;
        app.Show();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

on my web site I want to have login/registration form in modal window done
Assume that I have login to system using PHP + MySQL, then, after I
I have a login window with a Sign In button which is set as
Hi I want to create a WCF service that have login method, which is
I have a working FTP system with android, but I want to be able
I'm developing a Windows Phone application and I have three screens: Main screen Login
I have a storyboard set up with working login and main view controller, the
As per question. So I have a main window (MainForm) load when application start.
I built a Login application in which I have 3 Windows Log In Windows
Windows 7 Firefox 10.0.1 I have simple setTimeout logic that I want to test

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.