为什么应该为 WPF、SL 和 WP7 使用 UI 模式框架?
过去一个月我一直在学习 SL,现在我将注意力转向 UI 模式框架,例如 Caliburn.Micro 和 MVVM-Light。
我最近参加了一个关于在 WPF 和 SL 中使用 MVVM 模式的会议。演示者使用简单的模式进行演示,没有任何 UI 框架——非常简单和直接。在演示中,他建议我们创建一个基础虚拟机,以便能够使用一些常见功能(由于时间原因无法获得更多细节 - 请随时澄清)。这是我想要使用 UI 模式框架的原因吗?
我的理解是,UI 模式框架有助于按照约定实现 MVVM 等模式,从而使开发人员不必担心这一点。否则我为什么要使用 UI 模式框架?
提前致谢!
I've been learning SL over the past month and have now shifted my focus toward UI Pattern Frameworks such as Caliburn.Micro and MVVM-Light.
I recently attended a session at a conference on Using the MVVM Pattern with WPF and SL. The presenter demonstrated using the pattern plain, without any UI Frameworks -- very simple and straight forward. In the presentation he recommended that we create a base VM to be able to use some common functionality (wasn't able to get more specifics due to time -- please feel free to clarify). Is this a reason why I would want to use a UI Pattern Framework?
My understanding is that UI Pattern Frameworks help implement patterns like MVVM by convention, thus allowing devs to not have to worry about that. Why else would I use a UI Pattern Framework?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
丰富,
对于业务应用程序 - 您的虚拟机很可能需要至少 2 个接口:
INotifyPropertyChanged
和INotifyDataErrorInfo
就像 Kieren 所说 - 实现
INotifyPropertyChanged
非常重要简单,几行代码。INotifyDataErrorInfo
有点多,但还不错。MVVM Light 是如此“轻”,我什至不确定它的意义是什么:) 对我来说 - 理解 MVVM 的人不需要这个。您可以查看它的源代码以了解它的作用,因为您很可能需要扩展该基类。
Caliburn,OTOH,是一个基于约定的框架,它允许您在不指定“绑定”和其他类似魔法的情况下进行绑定。您需要决定是否真的需要它...
如果您正在处理一些繁重的事情,例如包含大量表单和内容的 LOB 应用程序 - 我强烈建议您研究一下 PRISM。它不是一个 MVVM 框架,而是构建复杂复合 UI 的框架。学习曲线会很陡,不像 MVVMLight :) 但它将涵盖您的业务应用程序中的大多数基础。
Rich,
For business app - your VM most likely going to need at least 2 interfaces:
INotifyPropertyChanged
andINotifyDataErrorInfo
Like Kieren said - implementing
INotifyPropertyChanged
is very easy, couple lines of code.INotifyDataErrorInfo
is little more but not bad.MVVM Light is so "light" I'm not even sure what's is the point :) To me - someone who understands what MVVM about doesn't need this. You can look at it's source code to see what it does because most likely you will need to expand on that base class.
Caliburn, OTOH, is a convention-based framework which allows you bind without specifying "Bindings" and other magic like this. You need to decide if you really need it...
If you are working on something heavy, like LOB application with lot's of forms and stuff - I strongly suggest looking into PRISM. It's not an MVVM framework, it's framework to build complex composite UI. Learning curve will be steep, not like MVVMLight :) But it will cover most bases in your business application.
使用 UI 模式框架的唯一原因是它是否提供了您需要或想要的功能。
如果您只需要使用
INotifyPropertyChanged
以及快速的RelayCommand
,请自己编写它们(因为它大约有 5 行代码,几个类,总共大约 30 行) 。如果您需要更多,请使用预构建的框架之一。
The only reason to use a UI Pattern Framework is if it provides the functionality you need or want.
If you only need to use
INotifyPropertyChanged
and maybe a quickRelayCommand
, write them yourself (since it's ~5 lines of code, a couple of classes, ~30 lines in all).If you need more, use one of the pre-built frameworks.