【发布时间】:2018-12-29 05:10:24
【问题描述】:
我目前正在尝试在一长串复选框项目上实现 ctrl 和 shift 选择功能。现在,您可以通过单击列表中的名称突出显示/选择项目,并且可以使用 ctrl 或 shift 选择组。但是,这不会影响复选框。如果选择中的项目已被选中/取消选中,我想通过选中/取消选中所有选定项目来允许组复选框切换。
这意味着尝试检索已选中/未选中的项目并比较其 IsSelected 属性。
This post 是我能找到的最接近我正在寻找的东西。
这是我现在拥有的 xaml:
<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>
以及部分对象类供参考:
public class MyObject : ObservableObject
{
// Fields
private string _id;
private string _fullName;
private string _name;
private bool _isChecked;
private bool _isVisible;
private bool _isSelected;
#region Constructors
#region Properties
}
【问题讨论】: