Caliburn ShowDialog和MessageBox [英] Caliburn ShowDialog and MessageBox

查看:70
本文介绍了Caliburn ShowDialog和MessageBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用caliburn制作MVVM的小型演示应用程序.

I'm making a small demo application for MVVM with caliburn.

现在,我想显示一个 MessageBox ,但使用MVVM方式.

Now I want to show a MessageBox, but the MVVM way.

对于对话框,我创建了一个事件,该事件在 ShellView (根视图)中处理并使用Dialogs ViewModel 类型调用 WindowManager.ShowDialog .似乎对我来说坚持使用MVVM.

For dialogs I created an event, that is handled in the ShellView (the root view) and just calls WindowManager.ShowDialog with a Dialogs ViewModel type. Seems to stick to MVVM for me.

但是显示消息框并获得其结果(好的还是取消的)的方式是什么?

But what is the way to show a messagebox and get its result (Okay or cancel)?

我已经看到这个问题,但是它也没有答案.

I already saw this question, but it contains no answer either.

艾森伯格先生自己的回答

Mr Eisenberg hisself answers with

"Caliburn具有内置的用于调用自定义消息框的服务."

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

任何人都可以说出他的意思吗?我没有在样本中看到它.

Can anyone tell what he means with that? I don't see it in the samples.

推荐答案

在文章

In the article A Billy Hollis Hybrid Shell (written by the framework coordinator) the author showed a nice way to handle both dialog and message boxes, but he used dependency injection (you can go without DI of course but it makes things simpler). The main idea is that you can let your main window, the one used as the application shell implement an interface that looks something like this:

public interface IDialogManager
    {

        void ShowDialog(IScreen dialogModel);
        void ShowMessageBox(string message, string title = null, MessageBoxOptions options = MessageBoxOptions.Ok, Action<IMessageBox> callback = null);

    }

然后他在IoC容器中注册了此接口,我想您可以从那里开始发挥您的想象力,如果您没有时间,可以看一下

and then he registers this interface with the IoC container, I guess you can use your imagination from there on and if you don't have time then you can look at the source code that accompanies the article.

这篇关于Caliburn ShowDialog和MessageBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆