Reputation: 889
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.
Upvotes: 0
Views: 2084
Reputation: 20899
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;
}
Upvotes: 1