I'm trying to find a `ToggleButton` associated in my CollectionViewGroup, my xaml structure is the following:
How you can see I've a `CollectionViewGroup` that filter the `ObservableCollection` binded `Matches` for `Nation` and `League`.
For this I've declared a `ListView` that have two `GroupStyle`, one that filter for `Country` and another for `League`, in this piece of code I add only the second GroupStyle (that contains the ToggleButton):
So, how you can see in the second group style (`Nation -> League`) I've a ToggleButton.
Now the GroupStyle will be repeated based on the items available in the `ObservableCollection`, so for example:
this is the organization, now imagine that for `Premier League` of `England` and for `Afghan Premier League` of `Afghanistan` there is a `ToggleButton` that I've inserted on the right, I need to get all the `ToggleButtons` of each `Group` available on the list. I tried this:
Essentially I extract the Group of the list and tried to find the ToggleButton on the nester group, but I cannot find it. Someone could help me?
Code:
<UserControl.Resources>
<CollectionViewSource Source="{Binding Matches}" x:Key="GroupedItems">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="MatchNation" />
<PropertyGroupDescription PropertyName="MatchLeague" />
</CollectionViewSource.GroupDescriptions>
</UserControl.Resources>
For this I've declared a `ListView` that have two `GroupStyle`, one that filter for `Country` and another for `League`, in this piece of code I add only the second GroupStyle (that contains the ToggleButton):
Code:
<ListView ItemsSource="{Binding Source={StaticResource GroupedItems}}">
<!-- this is the second group style -->
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="True" Background="#4F4F4F">
<Expander.Header>
<DockPanel Height="16.5">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="White" FontSize="11.5" VerticalAlignment="Bottom" />
<ToggleButton Checked="{Binding IsFavourite}" HorizontalAlignment="Right"/>
</DockPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
Now the GroupStyle will be repeated based on the items available in the `ObservableCollection`, so for example:
Code:
|England
|Premier League
1. item
2. item
3. item
|Afghanistan
|Afghan Premier League
1. item
2. item
Code:
var playingListSource = (ListCollectionView).Playing.Items.SourceCollection;
foreach (var gp in playingListSource.Groups)
{
var rootGroup = (CollectionViewGroup)gp; //Convert the nested group
var parentGroup = rootGroup.Items;
}