1

I have a LoginWindows, that run in startup.

I have a enterButton ,when click it, send a parametr to mainwindows and show it then hide self.

   public RelayCommand EnterCommand { get; set; }
   ...
    public LoginViewModel()
    {
        EnterCommand = new RelayCommand(() => Enter());

    }

    private object Enter()
    {
     //Show MainWndow
     }

What is the best way to open a new window from the viewmodel in mvvmLight?

ar.gorgin
  • 4,765
  • 12
  • 61
  • 100

1 Answers1

1

It is Useful answer. https://stackoverflow.com/a/16994523/970404

Concepts:

  • Registering Multiple VM's with the SimpleIoC and using GetInstance(...) to request them out.
  • Messenger class usage with a custom message type OpenWindowMessage
  • Opening Modal / Non Modal Windows from a parent VM staying true to the MVVM principles
  • Passing data between windows(just shown in NonModal)

Important Note:

The method used in this example to set the non DP DialogResult from the modal window is not MVVM friendly cos it uses code-behind to set the DialogResult property on a Window.Closing event which should be avoided(If needing to be "testable"). My preferred approach is a bit long and is very well documented HERE(Mixture of question and answer). Hence why I ignored it for the sake of this sample.

Community
  • 1
  • 1
ar.gorgin
  • 4,765
  • 12
  • 61
  • 100