使用 Caliburn MVVM 干净地分离 UI
研究 SL 的各种 MVVM 框架。在 Caliburn 文档中,我看到控制器中调用 MessageBox 的代码。这是正确的还是这只是为了介绍? Caliburn 中是否有类似 Chinch MVVM 中的 MessageBox 服务?
Looking into various MVVM frameworks for SL. In the Caliburn documentation I saw a code in a controller that calls MessageBox. Is this right or is this just for intro? Is there something like MessageBox service in Caliburn like in Chinch MVVM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这确实是介绍性代码,只是为了证明控制器方法实际上被执行了。然而,我同意您指出的问题:演示者中原始 UI 代码的存在可能会导致视图问题的不适当组合。
关于 MessageBox 服务:在 Caliburn v2 (trunk) 的 ShellFramework 模块中,有一个问题/答案 ViewModel 抽象了 MessageBox 的功能,其优点是可以让您设计对话框的 UI。
此外,创建您自己的 IMessageBox 抽象并使用默认的 WPF MessageBox 提供基本实现也非常简单。
It's indeed introductive code, just to demonstrate that the controller method is actually executed. Yet, I agree on the issue you pointed out: the presence of raw UI code in the presenter could lead to an inappropriate mix of view concerns.
About the MessageBox service: in Caliburn v2 (trunk), ShellFramework module, there is a Question/Answer ViewModel abstracting the functionality of a MessageBox, with the advantage of letting you to design the UI for the dialog.
Also, it's very straightforward to roll your own IMessageBox abstraction and provide a basic implementation using the default WPF MessageBox.
马可是对的。这只是为了证明该操作被调用。在实践中我不会推荐这样做。我将尝试对示例进行一些更改或添加一些注释以使这一点更加清晰。 Caliburn 具有用于调用自定义消息框的内置服务。
Marco is correct. This is just to demonstrate that the action is called. I wouldn't recommend this in practice. I will try to make some changes to the samples or add some comments that make this clearer. Caliburn has services built-in for calling custom message boxes.