在MVVM只能有一个View为每一个视图模型?视图、有一个、模型、MVVM

2023-09-03 07:34:41 作者:人不风流枉骚年.*

当我读到这里:

http://msdn.microsoft.com /en-us/library/gg405484(v=pandp.40).aspx

有典型一对一的   一个视图及其关系   视图模型。

There is typically a one-to-one relationship between a view and its view model.

这意味着,通过设计他们并不真正应对多种看法?

It means that by design they don't really cope with multiple views ?

推荐答案

我觉得这通常是在实践中的情况。然而,分离presentation到视图的美丽和视图模型意味着你可以很容易地创建很多不同的意见,从模型中的每个显示数据基本一致,都共享同一个视图模型类(可能或可能不一样实例的)。例如,我可以有一个的简单和高级的查看我的数据,在XAML大多写成两个完全不同的用户控件的,两者共享同一个视图模型(类或者实例) 。如果不使用MVVM这将是棘手做没有重复code。

I think this is usually the case in practice. However, the beauty of separating the presentation into a View and a ViewModel means that you could easily create many different Views, each showing basically the same data from the Model, all sharing the same ViewModel class (maybe or maybe not the same instance). For example, I could have a simple and advanced View of my data, written mostly in XAML as two completely different UserControl's, both sharing the same ViewModel (class or maybe instance). Without using MVVM this would be trickier to do without duplicating code.

 
精彩推荐
图片推荐