gpt4 book ai didi

c# - Caliburn ShowDialog 和 MessageBox

转载 作者:太空狗 更新时间:2023-10-30 00:25:21 25 4
gpt4 key购买 nike

我正在使用 Caliburn 为 MVVM 制作一个小型演示应用程序。

现在我想显示一个 MessageBox,但是是 MVVM 方式。

我为对话框创建了一个事件,该事件在 ShellView( Root View )中处理并且只需使用 Dialogs ViewModel 类型调用 WindowManager.ShowDialog。对我来说似乎坚持使用 MVVM。

但是显示消息框并获得结果(确定或取消)的方式是什么?

我已经看到了 this question , 但它也不包含任何答案。

艾森伯格先生亲自回答

"Caliburn has services built-in for calling custom message boxes."

谁能说出他的意思?我没有在示例中看到它。

最佳答案

如您所述,您只需准备 View 模型(例如 ConfirmationBoxViewModel)和适当的 View 。您必须创建两个操作(在从 Screen 继承 View 模型之后,这是使用 TryClose 所必需的)。您始终可以实现 IScreen相反,但那样会更费力):

public void OK()
{
TryClose(true);
}

public void Cancel()
{
TryClose(false);
}

然后在您的其他 View 模型中:

var box = new ConfirmationBoxViewModel()
var result = WindowManager.ShowDialog(box);
if(result == true)
{
// OK was clicked
}

请注意,在对话框关闭后,如果您需要从对话框中提取其他数据(例如所选项目、显示名称等),您可以访问 View 模型属性。

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

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