3

我发现 Show.MessageBox() 存在问题。

在我的应用程序中,我在几个地方调用 Show.Dialog() 以模态显示子窗口。

然后,如果您在新的子窗口中使用 Show.MessageBox(),则消息框将出现在应用程序主窗口上方的中心。你可以放一个断点,消息框的所有者也是主窗口。

为了解决这个问题,我用 IQuestionDialog 做了一个 hack:

    [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();
        }
    }

这不适用于所有可能的情况,但适用于我的应用程序。

任何更清洁的方法来解决这个问题?

4

1 回答 1

1

最新版本的 Caliburn 中的 DefaultWindowManager 没有这个问题。

于 2010-11-22T14:13:47.753 回答