Example #1
0
        /// <summary>
        ///     Lazy initialization of the window
        /// </summary>
        /// <returns>Actual view</returns>
        private DialogWindow GetWindow()
        {
            lock (LockObject)
            {
                if (window != null)
                {
                    return window;
                }

                // Set owner to MainWindow in order to prevent that MainWindow hides the DialogWindow upon minimizing the application
                window = new DialogWindow {Owner = Application.Current.MainWindow};

                window.Closed += (sender, e) =>
                {
                    if (Closed != null)
                    {
                        Closed(sender, e);
                    }

                    window = null;
                };

                window.Closing += (sender, e) =>
                {
                    if (Closing != null)
                    {
                        Closing(sender, e);
                    }
                };
                return window;
            }
        }
Example #2
0
        public void Close(bool dialogResult)
        {
            if (dialogResult)
                DialogResult = true;

            GetWindow().Close();
            window = null;
        }
Example #3
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;
            }
        }