Caliburn - ShellFramework - Show.MessageBox

I found a problem with Show.MessageBox ().

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

Then, if you use Show.MessageBox () in a new child window, a message box appears centered above the main application window. You can place a breakpoint, and the owner of the message box is also the main window.

To fix this, I made 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 will not work for all possible cases, but it works for my application.

Any cleaner way to fix this?

+3
source share
1 answer

DefaultWindowManager in the latest version of Caliburn does not have this problem.

+1
source

Source: https://habr.com/ru/post/1775733/


All Articles