Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caliburn - ShellFramework - Show.MessageBox

I've discovered an issue with Show.MessageBox().

In my application, I call Show.Dialog() in several places to display child windows modally.

Then if you use Show.MessageBox() in the new child window, the message box appears centered above the main window of the application. You can put a break point, and the owner of the message box is the main window as well.

To fix it, I did a hack with IQuestionDialog:

    [Singleton(typeof(IQuestionDialog))]
    public class QuestionDialogViewModel : Caliburn.ShellFramework.Questions.QuestionDialogViewModel    
    {
        public override void AttachView(object view, object context)
        {
            Window window = view as Window;
            if (window != null)
            {
                Window owner = GetTopWindow();
                if (owner != null)
                {
                    window.Owner = owner;
                }
            }

            base.AttachView(view, context);
        }

        private Window GetTopWindow()
        {
            //We have to get the next to last window in the list, the MsgBox will be the last
            return Application.Current.Windows
                .Cast<Window>()
                .Reverse()
                .Skip(1)
                .FirstOrDefault();
        }
    }

This won't work for all possible cases, but works for my application.

Any cleaner way to fix this?

like image 718
jonathanpeppers Avatar asked Dec 09 '25 08:12

jonathanpeppers


1 Answers

DefaultWindowManager in latest revision of Caliburn doesn't have this issue.

like image 149
jonathanpeppers Avatar answered Dec 11 '25 22:12

jonathanpeppers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!