Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

Not able to find ToggleButton in CollectionViewGroup

$
0
0
I'm trying to find a `ToggleButton` associated in my CollectionViewGroup, my xaml structure is the following:

Code:

<UserControl.Resources>
        <CollectionViewSource Source="{Binding Matches}" x:Key="GroupedItems">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="MatchNation" />
                <PropertyGroupDescription PropertyName="MatchLeague" />
            </CollectionViewSource.GroupDescriptions>
    </UserControl.Resources>

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):

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>

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:

Code:

|England
        |Premier League
        1. item 
        2. item
        3. item
    |Afghanistan
        |Afghan Premier League
        1. item
        2. item

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:

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;
    }

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?

Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>