Binding a nested ListBox to a nested list?

I have the following ViewModel property:

public List<List<string>> Names .... //It a dependency property 

In my opinion, I need an ItemsControl having an 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> 

How can I bind List items? In the sampel code above, I designated it ?????

+6
source share
1 answer

Just use the binding to the current binding source:

 ItemsSource="{Binding}" 

See comments below:

 <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> 
+6
source

Source: https://habr.com/ru/post/902563/


All Articles