gpt4 book ai didi

c# - Caliburn - ShellFramework - Show.MessageBox

转载 作者:行者123 更新时间:2023-11-30 18:07:08 24 4
gpt4 key购买 nike

我发现 Show.MessageBox() 有问题。

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

然后,如果您在新的子窗口中使用 Show.MessageBox(),则消息框会出现在应用程序主窗口的中央。可以打断点,消息框的主人也是主窗口。

为了修复它,我对 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();
}
}

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

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

最佳答案

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

关于c# - Caliburn - ShellFramework - Show.MessageBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4219667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com