Example #1
0
 public bool? ShowDialog(ViewModelBase viewModel)
 {
     lock (lockObject)
     {
         var window = GetWindow(viewModel, true);
         window.DataContext = viewModel;
         return window.ShowDialog();
     }
 }
Example #2
0
        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();
                }
            }
        }
Example #3
0
 public void ShowWindow(ViewModelBase viewModel)
 {
     lock (lockObject)
     {
         var window = GetWindow(viewModel, false);
         window.DataContext = viewModel;
         window.Show();
     }
 }
Example #4
0
        private Window GetWindow(ViewModelBase viewModel, bool isDialogWindow)
        {
            lock (lockObject)
            {
                var window = openedWindows.SingleOrDefault(w => w.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) =>
                {
                    if (Closed != null)
                    {
                        Closed(sender, e);
                    }

                    openedWindows.Remove(window);
                    window = null;

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

                window.Closing += (sender, e) =>
                {
                    if (Closing != null)
                    {
                        Closing(sender, e);
                    }
                };
                return window;
            }
        }
Example #5
0
 public bool? ShowDialog(ViewModelBase viewModel)
 {
     GetWindow().DataContext = viewModel;
     return GetWindow().ShowDialog();
 }