Caliburn - Shell 框架 - Show.MessageBox

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

这种方法并不适用于所有情况,但对于我的应用程序有效。

有没有更简洁的方法来解决这个问题?


Rob将会研究如何在Caliburn中修复它:http://caliburn.codeplex.com/workitem/7701。在此期间,有人有更简洁的解决方案吗? - jonathanpeppers
1
在DefaultWindowManager中添加了一个更好但不是理想的实现,该实现负责创建子窗口和对话框:http://caliburn.codeplex.com/Thread/View.aspx?ThreadId=235325 - Marco Amendola
我将尝试新版本,之后会告诉你。 - jonathanpeppers
1个回答

1

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接