Silverlight-MVVM良好实践示例 [英] Good Silverlight-MVVM Practice Example

查看:68
本文介绍了Silverlight-MVVM良好实践示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了许多有关Model-View-ViewModel模式的好文章,我的团队打算在我们应用程序的最新版本中实现此模式.我仍然不太了解如何完成这项工作.我想找到我可以解决的这种模式的一个很好的例子.小规模的事情,就像Jason Dolinger在他的视频中在这里所做的一样,但我想我可以以较慢的速度自行解决的问题.

I've read a number of good articles about the Model-View-ViewModel pattern and my team intends to implement this pattern in the latest version of our app. I still don't quite get ALL the bits that go together to make this work. I'd like to find a good example of this pattern that I can work through. Something on a small scale, much like Jason Dolinger does in his video here, but I'd like something that I can work through on my own at a slower pace.

预先感谢您的帮助.

推荐答案

基本上,ViewModel是模型的包装.某人说,现在这可能还不是很有帮助:-)将模型视为您的应用程序使用的数据.现在,一个人有一个生日,您可能需要一个表格来输入该人的生日.假设我们只是使用一个简单的TextBox,日期显示为01-02-2009 12:00:00 AM.对于初学者,我们不需要时间部分,我们也可能不会对01-02-2009部分感到满意​​,因为这取决于您的区域设置.

Basically a ViewModel is a wrapper around model. Now that might not be very helpful yet :-) Think of the model as the data your application works with, say a person. Now a person has a birthday and you might want to have a form to enter the person's birthday. Suppose we are just using a simple TextBox the date shows up something like 01-02-2009 12:00:00AM. For starters we don't want the time part and we also might not be to happy about the 01-02-2009 part as this depends on your locale settings.

因此,ViewModel随即出现.它包装Person类,并将日期显示为三个整数值:年,月和日.在属性集中,它尝试使用不同的值构建日期,并显示可能发生的任何错误.

So here the ViewModel comes im. It wraps the Person class and exposed the date as three integer values, year, month and day. In the property set it tries to build a date from the different values and displays any errors that might occur.

因此,简单地说,ViewModel是专门针对特定视图(显示)的Model包装器.它同时消除了大多数IValueConvertor.

So simply said a ViewModel is a Model wrapper specifically geared towards a particular view (display). It eliminates most IValueConvertors at the same time.

乔什·史密斯(Josh Smith)在这里有一个很好的解释: http://joshsmithonwpf.wordpress.com/2008/11/14/using-a-viewmodel-to-provide-有意义-验证错误消息,并在此处进行了大讨论: http://groups.google.com/group/wpf-门徒/browse_thread/thread/3fe270cd107f184f?pli = 1

Josh Smith has a nice explanation here: http://joshsmithonwpf.wordpress.com/2008/11/14/using-a-viewmodel-to-provide-meaningful-validation-error-messages and a big discussion here: http://groups.google.com/group/wpf-disciples/browse_thread/thread/3fe270cd107f184f?pli=1

这篇关于Silverlight-MVVM良好实践示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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