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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:36:12+00:00 2026-06-06T05:36:12+00:00

When a user has entered a correct password, a login window should close and

  • 0

When a user has entered a correct password, a login window should close and the main window should open. I would like to do this from the ViewModel, however, the ViewModel may not know anything about the view.

I’ve searched a lot and apparantly the best way is to use the mediator pattern. I understand how this pattern works, but how to effectivly use it in this case?

the mediator will need:
– A reference to the View
– A reference to the ViewModel

The ViewModel will need a reference to the mediator.

Where do I need to create the mediator? I can’t do it in the ViewModel as I won’t be able to set the reference to the view. Creating the mediator in the view is an option as I can get the ViewModel out of the DataContext property, but then I will still need to pass the mediator to the ViewModel, which will only make the code more difficult.

How do I properly use a mediator for opening/closing windows?

  • 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-06T05:36:14+00:00Added an answer on June 6, 2026 at 5:36 am

    the mediator pattern is used for communication between viewmodels not between view and viewmodel.

    if you wanna handle dialogs from your viewmodel you can use a dialogservice like this one.

    nevertheless when i wanna create a application login dialog, i do it this way.

    in app.xaml.cs OnStartup()

    • create loginview
    • create login viewmodel
    • set datacontext for loginview to loginviewmodel
    • show loginview
    • EDIT: loginviewmodel check password and so on, if its ok then state is set in the loginviewmodel e.g. IsValidUser=true;
    • check result
    • EDIT: if dialogresult == “OK” and IsValidUser=true
    • the open mainwindow

    here some of my code

        protected override void OnStartup(StartupEventArgs e)
        {
            //...
            ShutdownMode = ShutdownMode.OnExplicitShutdown;
            var vm = new LoginVM();
            var loginwindow = new LoginWindow();
            loginwindow.DataContext = vm;
    
            if (!result.HasValue || !result.Value || !IsValidUser)
            {
                 Shutdown();
                 return;
            }   
    
            //...
            var mainWindow = new MainWindow(new MainWindowViewModel(vm.Settings));
    
            mainWindow.Loaded += (sender, args) => splashScreen.Close();
            this.MainWindow = mainWindow;
            ShutdownMode = ShutdownMode.OnMainWindowClose;
            this.MainWindow.Show();
    
     }
    

    ps: this is the only part of my apps where i use view first. the rest is all viewmodel first, which is much easier for me when doing mvvm.

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

Sidebar

Related Questions

I use php with ajax. <?php /* * Suppose, user has entered both correct
I have this code below which checks whether the user has entered a syntactically
In a login system, how can you tell if the user has entered the
I need to move text that the user has entered into a large multi-line
Is it possible to get the email address which the user has entered? I
THIS USER HAS ALREADY ASKED THE EXACT DUPLICATE A FEW MINUTES AGO sql and
Once a user has selected a file with the open file dialog, how can
1.) I have a code script to check if the user has entered a
I am trying to validate an email address user has entered. I've done the
How to check if the user has entered the page by clicking on the

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.