I'm currently trying to implement ctrl & shift selection capabilities on a long list of checkbox items. Right now, you can highlight/select items by clicking on the names in the list, and you can select groups by using ctrl or shift. I'd like to allow group checkbox toggling by checking/unchecking all selected items if an item in the selection has been checked/unchecked.
This means trying to retrieve the item that was checked/unchecked and comparing its IsSelected property.
This post is the closest thing I could find to the what I'm looking for.
This is the xaml I have right now:
<ListView Name="LeftListView"
Grid.Row="4" Grid.Column="1"
ItemsSource="{Binding CvsLeftListView}">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<VirtualizingStackPanel Orientation="Horizontal">
<CheckBox Name="LeftListCheckBox"
IsChecked="{Binding Path=IsChecked, Mode=TwoWay}"
Command="{Binding Path=DataContext.CheckBoxChanged, RelativeSource={RelativeSource AncestorType=ListView}}"
Checked="LeftListCheckBox_Checked" Unchecked="LeftListCheckBox_Unchecked"/>
<TextBlock Name="LeftListName"
Text="{Binding Name}"
Margin="2,0,0,0"/>
</VirtualizingStackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Aucun commentaire:
Enregistrer un commentaire