Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
This repository was 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

Description

@ameaninglessname

`///


/// 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;
        }
    }`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions