firstfloorsoftware / mui

Modern UI for WPF
Microsoft Public License
2.6k stars 755 forks source link

Show ModernDialog in a non-modal way, (call Show()) lead to a InvalidOperationException, Should Check if it is modal before assign DialogResult #189

Open ameaninglessname opened 5 years ago

ameaninglessname commented 5 years ago

`///

/// Initializes a new instance of the class. /// public ModernDialog() { this.DefaultStyleKey = typeof(ModernDialog); this.WindowStartupLocation = WindowStartupLocation.CenterOwner;

        this.closeCommand = new RelayCommand(o => {
            var result = o as MessageBoxResult?;
            if (result.HasValue) {
                this.messageBoxResult = result.Value;

                if (System.Windows.Interop.ComponentDispatcher.IsThreadModal)//**....Here!!!**
                {
                    // sets the Window.DialogResult as well, if windows is called by ShowDialog()
                    if (result.Value == MessageBoxResult.OK || result.Value == MessageBoxResult.Yes)
                    {
                        this.DialogResult = true;
                    }
                    else if (result.Value == MessageBoxResult.Cancel || result.Value == MessageBoxResult.No)
                    {
                        this.DialogResult = false;
                    }
                    else
                    {
                        this.DialogResult = null;
                    }
                }
            }
            Close();
        });

        this.Buttons = new Button[] { this.CloseButton };

        // set the default owner to the app main window (if possible)
        if (Application.Current != null && Application.Current.MainWindow != this) {
            this.Owner = Application.Current.MainWindow;
        }
    }`