Silverlight 和 MVVM 中实现最佳性能的最佳实践是什么
我有很多标准化表 - 可能超过 50 个...我想知道定义 ViewModel 的最佳方法是什么 - 为每个表单单独的 ViewModel 或为多个表单创建 Common ViewModel。因为制作单独的表单可能会增加需要下载的数据的大小,并且可能会增加客户端上数据的冗余。即在每个表单上使用类别都有不同的数据集。另一方面,为一组表单创建通用视图模型可能会增加管理内容的复杂性。
是否有任何适当的文章描述开发的这一方面?管理整个应用程序以提供最佳性能的最佳实践是什么? (从服务器获取最少数据)
感谢您的时间和帮助。
I have many Normalized tables - might be more than 50... I was wondering what is the best approach for defining ViewModels - individual ViewModel for each form or making Common ViewModel for multiple Forms. Because making individual forms might increase the size of the data that needs to be downloaded and it might increase the redundancy of data on the client. i.e. using Category on each form has different set of data for each of them. and On the otherside making common viewmodel for set of Forms might increase the complexity in managing stuff.
Is there any proper article describing such aspect of Development. What is the best practices for managing overall Application so that it will offer optimal performance. (Fetching minimum Data from Server)
Thanks for your time and help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览量和浏览量模型会增加 XAP 文件,在打开时完全下载,这可以是 压缩。使用过程中的实际性能有所不同,并且还取决于其他因素,请尝试使用 SilverlightSpy了解实际的浏览器性能。可以根据需要下载部分 silverlight 应用程序,但这是一项高级技术。
如果消息传递是您主要关心的问题,请查看二进制消息传递。
我建议为每个视图或嵌套用户控件使用新的 ViewModel,然后使用 事件聚合器,用于模型之间的通信。
The amount of views & models will increase the size of your XAP file, which is downloaded completely on open, this can be compressed. Actual performance during use is different and depends on other factors as well, try using SilverlightSpy to get an idea of actual browser performance. It is possible to download parts of your silverlight app as required, but this is an advanced technique.
If Messaging is your main concern, then check out Binary Messaging.
I recommend using a new ViewModel for every view, or nested Usercontrol, then use an event aggregator for communication between models.
通常,您需要为每个视图创建一个视图模型。如果两个视图显示相同的数据并允许用户执行相同的操作,但仅在 UI 实现方面有所不同,那么它们可以共享视图模型,但目标是保持视图模型的内聚性。如果您的视图模型包含操作多个视图的代码,您将面临实现“上帝对象”反模式的风险。如果您发现视图模型都共享一定数量的公共代码,请考虑将该代码移至公共基类。
请记住,两个完全不同的视图模型可以操作相同的模型。如果两个视图显示相同的数据,但每个视图都允许用户以独特的方式与其交互,则可能会出现这种情况。
我强烈推荐阅读 Gary Hall 撰写的Pro WPF 和 Silverlight MVVM。这是一本很棒的 MVVM 入门书籍,特别是与 WPF 和/或 Silverlight 一起使用时。
Typically you'll want to create a View Model for each View. If two Views display the same data and allow the user to perform the same actions but differ only in UI implementation then they can share a View Model but the goal is to keep your View Models cohesive. If your View Models contain code to operate multiple views you run the risk of implementing the "God Object" anti-pattern. If you find that your View Models all share a certain amount of common code, consider moving that code to a common base class.
Remember that two completely different View Models can manipulate the same Models. This might be the case if two views display the same data but each allows the user to interact with it in a unique way.
I would highly recommend reading Pro WPF and Silverlight MVVM by Gary Hall. It's a great book to get started with MVVM, particularly for use with WPF and/or Silverlight.