Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

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 this issue Dec 13, 2018 · 0 comments

Comments

@ameaninglessname
Copy link

`///


/// 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;
        }
    }`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant