0

I have two list views, a parent that contains a child list view with its item template.

<ListView Name="TopView">
    <ListView.ItemTemplate>
        <DataTemplate>
             <ListView ItemsSource="{Binding SubList}"Focusable="False">
                  <ListView.Background>
                        <SolidColorBrush Color="Transparent"/>                                                  
                  </ListView.Background>
                  <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid HorizontalAlignment="Stretch">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="50" />
                                    <ColumnDefinition Width="50" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding Path=Number}" Grid.Column="0" />
                                <TextBlock Text="{Binding Path=Type}" Grid.Column="1" />
                                <TextBlock Text="{Binding Path=Code}" Grid.Column="2"  />
                            </Grid>
                        </DataTemplate>
                  </ListView.ItemTemplate>
             </ListView>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Whenever attempting to use TopView.SelectedValue, the value returned is always null.

How can I make the parent ListView be the only ListView to accept selection events instead of the child ListView? I figure I need to do something with event routing but I'm not sure what.

Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
Peter Smith
  • 849
  • 2
  • 11
  • 28
  • you have no itemsource defined for your outer listview, so it will return null. Whatelse should it return? – dognose Dec 13 '12 at 15:57
  • @dognose I add items manually to the top list view in the constructor via TopView.Items.Add so I figured it would return the selected item\value via that collection. – Peter Smith Dec 13 '12 at 15:59
  • You can refer [Databinding for nested collections in XAML (WPF and Silverlight) - WebX - Site Home - MSDN Blogs](http://blogs.msdn.com/b/harryh/archive/2010/06/12/nested-collections-databinding-in-xaml-wpf-and-silverlight.aspx) – amit jha Jul 20 '15 at 08:56

1 Answers1

1

Ok, did not expect that you mix databinding with manual filling. I assume that your inner Listview consumes the select-event. You'll have to bubble that one up in the tree until you hit TopView. set the e.handled property in the inner Listview's handler to false after processing it should raise the event for the next listview, iirc.

private void handleInner(object o, RoutedEventArgs e)
{
    InnerControl innerControl = e.OriginalSource as InnerControl;
    if (innerControl  != null)
    {
        //do whatever
    }
    e.Handled = false;
}
dognose
  • 20,360
  • 9
  • 61
  • 107