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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:51:37+00:00 2026-05-30T23:51:37+00:00

I’m making a WPF application making use of the MVVM light framework. What I’m

  • 0

I’m making a WPF application making use of the MVVM light framework.

What I’m trying to do is have a login form in a view, when the user presses a button within that view it launches a LoginCommand for the attached ViewModel. From there I either want to launch a new window which holds the rest of the application, or simply switch views from the same window.

Currently I have it so that there is a view called MainView which has a content control inside bound to View1. However to switch to View2 I need to put the button for this on MainView, and not within View1 where it belongs.

Any advice?

  • 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-30T23:51:39+00:00Added an answer on May 30, 2026 at 11:51 pm

    Usually I do this one of two ways:

    If the login window is a one-time thing required before starting the application, I will put it in the OnStartup() method of the Application object

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
    
        // Login
        var login = new LoginDialog();
        var loginVm = new LoginViewModel();
    
        login.DataContext = loginVm;
        login.ShowDialog();
    
        if (!login.DialogResult.GetValueOrDefault())
        {
            // Error is handled in login class, not here
            Environment.Exit(0);
        }
    
        // If login is successful, show main application
        var app = new ShellView();
        var appModel = new ShellViewModel();
    
        app.DataContext = viewModel;
        app.Show();
    }
    

    The other way I usually do this is through a ShellViewModel or ApplicationViewModel which handles all my window management. This method uses DataTemplates to define each screen, and uses a ContentControl as a placeholder for the current screen in the ShellView or ApplicationView.

    I usually combine this with an Event System of some kind, like Microsoft Prism’s EventAggregator, so it can listen for messages of a specific type, such as OpenWindow or CloseWindow messages. If you’re interested, I have a blog post about Communication between ViewModels that should give you a better idea of what an event system looks like.

    For example, my ShellViewModel might start by displaying a LoginViewModel (a DataTemplate is used to tell WPF to draw the LoginViewModel with the LoginView), and it would subscribe to receive messages of type SuccessfulLogin. Once the LoginViewModel broadcasts a SuccessfulLogin message, the ShellViewModel will close the LoginViewModel and replace it with the ApplicationViewModel. You can see an example of this in my article on Navigation with MVVM

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.