Opening a new window in WPF C#

Oct 2 2012 4:46 PM
Hi guys,
I'm Pretty new to WPF and I'm working on a project where I need to have the user log in before the main window is shown.
in my app.xml I've set the startupurl to login.xaml and using stored procedures I'll validate this user.
the issue is actualy closing the login form and opening the main window.
I've created a Command in my viewmodel that will call a method in App.xaml.cs

((App)Application.Current).LoadMainWindow(MUser);

this is the actual method

public void LoadMainWindow(clsMUsers user)
{
    this.CurrentUser = user;
               
   Login login = (Login)App.Current.MainWindow;

   login.Close();

    MainWin main = new Mainwin();

    //App.Current.MainWindow = main;
    

    main.Show();

}

this is starting to drive me crazy.

as stated before I need to be able to close the login form and set the new "main" window as the application mainwindow but nomatter what I try it will either open another login form, open both the 'main' window and a new login form.

I'm not looking for a copy/paste ready to go piece of code, any suggestions on how to tackle this issue will be much appreciated.

thanks in advance.
Marco