我有一個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