【发布时间】:2014-05-04 10:30:41
【问题描述】:
我有一个 XYZ 类型的对象和一个视图模型 XYZViewModel。我有这个对象的数据模板
<DataTemplate DataType="{x:Type vm:XYZViewModel}">
<Grid>
/ some ui
</Grid>
</DataTemplate>
我有一个视图模型“ListXYZViewModel”,其中包含“XYZViewModel”列表。现在我应该显示这些对象的列表。
最好的方法是什么? 我想在包装面板中显示它。我这样做了
<ItemsPanelTemplate x:Key="WrapPanelTemplate">
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
<DataTemplate DataType="{x:Type vm:ListXYZViewModel}">
<Grid>
<ItemsControl ItemsSource="{Binding HomeViewModel}" ItemsPanel="{StaticResource WrapPanelTemplate }"></ItemsControl>
</Grid>
</DataTemplate>
这不起作用。有什么建议吗?
【问题讨论】:
-
HomeViewModel 本身是一个集合还是您的意思是将 ItemsSource 绑定到集合上?
-
HomeViewModel 是 XYZViewModel 的 ObservableCollection 对象