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

查看:29
本文介绍了良好的 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:00AM.首先,我们不想要时间部分,我们也可能对 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 是一个专门针对特定视图(显示)的模型包装器.它同时消除了大多数 IValueConvertors.

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-meaningful-validation-error-messages 和这里的一个大讨论: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天全站免登陆