我有一个ListView绑定到一些数据,它被分组和排序。我添加了一个复选框向分组报头,像这样:分组列表视图与复选框在标题
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,0,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="True" BorderBrush="#FFA4B97F" BorderThickness="0,0,0,1">
<Expander.Header>
<DockPanel>
<CheckBox>
<StackPanel Orientation="Horizontal">
<TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0"/>
<TextBlock Text=" ("/>
<TextBlock Text="{Binding Path=ItemCount}"/>
<TextBlock Text=" Items)"/>
</StackPanel>
</CheckBox>
</DockPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
现在我只关心并需要通过有头检查分组的项目的方式来循环,什么是完成这一任务的最好方法是什么?
是的,谢谢你,我可以把它变成一个可行的解决方案。然而,我真的只是在列表填充之后寻找一种方法来获取包含选项框复选框的组列表。相反,不管使用你的代码,我只需要一个带有复选框的不可见列作为正在显示的类的成员,并根据哪个组已被选中来控制复选框,然后很容易找到哪些项目被检查,哪些不是。再次感谢你! – acat13
你可以得到所有组,我认为'ListView'暴露了'Items'属性...我想这应该有个别组....这是一个新人猜测,它可能不会赢得你的德比。 :-) –
在.NET 4中,它不是GroupItem,而是CollectionViewGroup – SACO