0

I'm trying to display a modal login dialog after the MainWindow has been shown. (Like in SSMS)

I know this is not the MVVM approach but I'm using MainWindow's Loaded event where I call following code:

private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
    ViewModel.ShowLoginDialog();
}

In the ViewModel I'm calling:

public void ShowLoginDialog()
{
    var vm = new LoginControlViewModel();
    var window = new LoginWindow(vm);
    window.ShowDialog();
}

Well the login dialog is shown, but the MainWindow only get's shown if the Dialog has been closed.

How do I display the MainWindow and the LoginDialog at the same time?

Stefan Schmid
  • 1,012
  • 10
  • 28
  • 1
    `Loaded` event occurs *before* window is shown. You could use to example [this](http://stackoverflow.com/a/14605461/1997232) answer solution to display something *after* window is rendered and for the first time only. – Sinatr Nov 06 '14 at 09:39

1 Answers1

1

You call dialog in constructor.If you use MVVM, I suggest you to use IDialogService. You can find it in many MVVM frameworks/libs or write your own easily. Also your problem is solved by this way.

Abdurrahman Alp Köken
  • 1,236
  • 1
  • 13
  • 12
  • Do you have an example of a custom DialogService? I've found http://uxprogramming.blogspot.de/2013/06/simple-mvvm-dialogservice.html but it's throwing an `InvalidOperationException` because the owner window has not been shown yet. – Stefan Schmid Nov 06 '14 at 08:05