Results 1 to 3 of 3

Thread: Not able to find ToggleButton in CollectionViewGroup

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2016
    Posts
    4

    Not able to find ToggleButton in CollectionViewGroup

    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?

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: Not able to find ToggleButton in CollectionViewGroup

    Since you're talking about XAML I assume this is WPF so I've moved it to the appropriate forum. If I've misunderstood that then please send me a pm.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2016
    Posts
    4

    Re: Not able to find ToggleButton in CollectionViewGroup

    Quote Originally Posted by FunkyDexter View Post
    Since you're talking about XAML I assume this is WPF so I've moved it to the appropriate forum. If I've misunderstood that then please send me a pm.
    Yes, is wpf -> c#. But the problem is relative to c#.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width