Binding a nested ListBox to a nested List?
Asked Answered
M

1

6

I have the following ViewModel-Property:

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

In my view I would like an ItemsControl that has 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 to the items of the List? In code sampel above I marked it with ?????

Margarettamargarette answered 28/11, 2011 at 14:14 Comment(0)
C
7

Simply use binding to the current Binding Source:

ItemsSource="{Binding}"

See some 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>
Claypool answered 28/11, 2011 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.