public void ShowWindow(ViewModelBase viewModel)
 {
     lock (lockObject)
     {
         var window = GetWindow(viewModel, false);
         window.DataContext = viewModel;             
         window.Show();
     }
 }
 public bool? ShowDialog(ViewModelBase viewModel)
 {
     lock (lockObject)
     {
         var window = GetWindow(viewModel, true);
         window.DataContext = viewModel;
         return window.ShowDialog();
     }
 }
        private Window GetWindow(ViewModelBase viewModel, bool isDialogWindow)
        {
            lock (lockObject)
            {
                var window = openedWindows.SingleOrDefault(x => x.DataContext == viewModel);

                if (window != null)
                {
                    window.WindowState = WindowState.Normal;
                    window.Activate();
                    return window;
                }

                if (isDialogWindow)
                {
                    // Set window owner in order to prevent that it becomes hidden when minimizing the application
                    window = new DialogWindow
                    {
                        Owner = openedWindows.Any() ? openedWindows.Last() : Application.Current.MainWindow
                    };
                }
                else
                {
                    // Doesn't need a window owner since it's shown in the taskbar
                    window = new StandardWindow();
                }

                openedWindows.Add(window);

                window.Closed += (sender, e) =>
                {
                    Closed?.Invoke(sender, e);

                    openedWindows.Remove(window);
                    window = null;

                    if (!openedWindows.Any() && Application.Current.MainWindow != null)
                    {
                        Application.Current.MainWindow.Activate();
                    }
                };

                window.Closing += (sender, e) =>
                {
                    Closing?.Invoke(sender, e);
                };
                return window;
            }
        }
        public void Close(ViewModelBase viewModel, bool dialogResult = false)
        {
            lock (lockObject)
            {
                var window = openedWindows.SingleOrDefault(w => w.DataContext == viewModel);

                if (window != null)
                {
                    if (dialogResult) window.DialogResult = true;

                    openedWindows.Remove(window);
                    window.Close();
                }
            }
        }