<ListView SelectionChanged="RecordSelected" Height="134" HorizontalAlignment="Left" Margin="10,10,0,0" Name="processList" VerticalAlignment="Top" Width="207">
<ListView.ItemTemplate>
<DataTemplate x:Name="record" DataType="{x:Type local:MyApp}">
<StackPanel Name="cell" Orientation="Vertical" KeyUp="cell_KeyUp">
<StackPanel KeyUp="cell_KeyUp" GotFocus="RecordSelected" KeyDown="RecordSelected" MouseDown="RecordSelected" Orientation="Horizontal" Tag="{Binding MyApp}">
<CheckBox BorderThickness="1" IsChecked="{Binding IsChecked}" Margin="3,3,3,3" Name="checkbox" />
<TextBlock GotFocus="RecordSelected" HorizontalAlignment="Left" KeyDown="RecordSelected" Margin="3,0,0,3" Name="displayname" Text="{Binding DisplayName}" VerticalAlignment="Center" Width="200" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I added a KeyUp event on both the stackpanels inside the datatemplate, but it wouldn’t fire.
The
KeyUpevent won’t trigger since it is theListViewItemthat has the focus. Subscribe to theKeyUpevent in theItemContainerStyleinsteadIn the event handler the sender will be the focused
ListViewItem. CastContentof it to your source and toggleIsChecked. This will work if your source class implementsINotifyPropertyChanged. Otherwise, you can search the Visual Tree to find the childCheckBoxof theListViewItem