WPF中的复合ViewModel [英] Composite ViewModels in WPF
问题描述
是否可以使视图模型由其他视图模型组成?在实践中这将如何工作?我有在多个视图中重用的数据,并且我有由几组数据组成的视图.因此,我基本上希望建立多对多关系 视图和视图模型之间的联系,而我的有限理解是,视图和视图模型之间的联系是一对多的.
Is it possible to have view model composed of other view models? How would this work in practice? I have data that is reused in several views and I have views that are made up several groups of data. So essentially I would like a many to many relationship between views and view models and my limited understanding is that it is a many to one relationshop between views and view models.
推荐答案
您为模板中所有视图提供的VM,您提到了将哪个视图关联到那里的VM之间的关系,您可以将5个视图设置为1个VM
you can you a VM for all your views in the templet you mention the relation between which view is assosiated to which VM there you can set up 5 views to 1 VM
<b;< DataTemplate DataType =" {x:Type vm:SelectListViewModel}"
<DataTemplate DataType="{x:Type vm:SelectListViewModel}">
< vw:SelectListView/>
<vw:SelectListView />
</DataTemplate>
</DataTemplate>
这篇关于WPF中的复合ViewModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!