我有以下ViewModel-Property:
public List<List<string>> Names .... //It's a dependency property
在我看来,我希望ItemsControl
有一个ItemsControl
:
<ItemsControl ItemsSource="{Binding Names}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ?????}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Text="{Binding ??????}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
如何绑定List
的项目?在上面的代码示例中,我用?????
答案 0 :(得分:6)
只需使用绑定到当前绑定源:
ItemsSource="{Binding}"
请参阅以下评论:
<ItemsControl ItemsSource="{Binding Names}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<! -- Here is the current binding source will be inner
List<string>
-->
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<! -- Here is the current binding wource will be
a string value from the inner List<string>
-->
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>