tags:

views:

621

answers:

2

I have this ListView in xaml

    <ListView x:Name="PersonsListView" ItemsSource="{Binding}" ItemTemplate="{DynamicResource personLayout}">
    <ListView.Resources>
        <DataTemplate x:Key="personLayout" DataType="Person">
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{Binding Path=FullName}"/>
                <ListView x:Name="AddressesListView" ItemsSource="{Binding Path=Addresses}"/>
            </StackPanel>
        </DataTemplate>
    </ListView.Resources>
</ListView>

How can I use AddressesListView in code behind? For instance if I want to do AddressesListView.SelecItem.

+2  A: 

Given an item in the PersonsListView that is of Type Person, you can use the ItemContainerGenerator property on the PersonsListView, and find the container for the data item. You should then bable to use FrameworkElement.FindName(), to find that specific element.

The nested listview looks kinda weird BTW :)

dhopton
dhopton: Can you explain me your last statement? thanks
Mariano
My statement about listviews containing other list views being odd? Sure -- it's just odd to see lists inside other lists... at least using full on list view controls (eg having N levels of selection). Just seems odd.
dhopton
Mariano