ModernDialog.ShowDialog Not returning true - ever

Aug 20, 2013 at 12:39 PM
I posted in the Issues section but did not know if this would be best to post here also so apologies in advance for posting in two places.

m:ui is Great BTW!!!

I have read this Discussion but there was never really an answer given.. Only that it works as re-designed. IMHO the re-design is flawed as you can no longer return the value from the ShowDialog method.

If you do this in 1.0.3 and you were to click the Ok Button you would see true returned - not the case in 1.0.5
var dialog = new ModernDialog {
                 Title = "Common Dialog",
                 Content = new LoremIpsum(),
             dialog.Buttons = new Button[] { dialog.CloseButton, dialog.OkButton };
             bool? r = dialog.ShowDialog();
We were using 1.0.3 to display a login form - and we want to upgrade but this is a problem.

Does anyone have a suggestion, if so please show or point to an example

And Then My Answer to my Own Question

have an answer to my own question but would like someone who is more familiar with WPF to answer if I am correct.

If you expose the dialogResult in ModernDialog.cs
/// <summary> 
        /// Return the Dialog Result when using the ShowDialog method.
        /// </summary>
        public MessageBoxResult GetDialogResult {
            get { return dialogResult; }
Because the actual DialogResult is never set or passed back as far as I can see.

You would then be able to do this
var  dialog = new ModernDialog
                    Title = "Common dialog",
                    Content = new LoremIpsum()
            dialog.Buttons = new Button[] { dialog.CloseButton,dialog.OkButton};

Do the Guru's agree?
Aug 20, 2013 at 2:52 PM
This may be better Alter ModernDialog.cs to do this
public ModernDialog()
            this.DefaultStyleKey = typeof(ModernDialog);
            this.WindowStartupLocation = WindowStartupLocation.CenterOwner;

            this.closeCommand = new RelayCommand(o => {
                var result = o as MessageBoxResult?;
                if (result.HasValue) {
                    this.dialogResult = result.Value;
                    if (result.Value == MessageBoxResult.OK || result.Value == MessageBoxResult.Yes) 
                        DialogResult = true;

            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;
Then when calling you could do this
MessageBox.Show((dialog.DialogResult).ToString()); // Would produce True when clicking Ok or Yes
Aug 22, 2014 at 8:39 AM
I ended up adding a click-event to the dialog.OkButton and did the "stuff" there, something like:
 var dialog = new ModernDialog { Title = "Save?", Content = "You made changed, want to save before exiting?" };
                var okButton = dialog.YesButton;
                okButton.Click += (sender, e1) => _vm.Save();
                dialog.Buttons = new[] { okButton, dialog.NoButton };
Works for me :)
Aug 22, 2014 at 10:14 AM
This ModernDialog issue has been fixed in release 1.0.6, a MessageBoxResult property has been added. No need to workaround anymore
Aug 22, 2014 at 10:59 AM

Sent from my Windows Phone