Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3356796
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:33:21+00:00 2026-05-18T02:33:21+00:00

In my WPF application I have a CollectionViewSource which is providing a view to

  • 0

In my WPF application I have a CollectionViewSource which is providing a view to a private ObservableCollection. The CollectionViewSource has a PropertyGroupDescription which is utilised in a ListBox to present data to the User’s preference.

Using a ControlTemplate containing a Expander Control within the ListBox GroupStyle, the result is quite nice. However, I would like to show the number of items in each group in the Expander Header in addition to the Group Name. Any ideas on the binding path?

Regards,
Liam

<Style x:Key="basicGroupStyle" TargetType="{x:Type GroupItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type GroupItem}">
                <Expander Header="{Binding Name}" IsExpanded="True">
                    <ItemsPresenter/>
                </Expander>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<ListBox ItemsSource="{Binding Source={StaticResource myViewSource}}">
    <ListBox.GroupStyle>
         <GroupStyle ContainerStyle="{StaticResource basicGroupStyle}"/>
    </ListBox.GroupStyle>
</ListBox>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:33:22+00:00Added an answer on May 18, 2026 at 2:33 am

    you have to use property ItemCount

    <Window x:Class="WpfApplication11.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
        <Window.Resources>
            <XmlDataProvider x:Key="data">
                <x:XData>
                    <Animals xmlns="">
                        <Animal name="Dory" Species="Fish" />
                        <Animal name="Felix" Species="Cat" />
                        <Animal name="Fluffy" Species="Dog" />
                        <Animal name="Jake" Species="Snake" />
                        <Animal name="Mittens" Species="Cat" />
                        <Animal name="Murtle" Species="Turtle" />
                        <Animal name="Nemo" Species="Fish" />
                        <Animal name="Rex" Species="Dog" />
                        <Animal name="Rover" Species="Dog" />
                        <Animal name="Toonces" Species="Cat" />
                    </Animals>
                </x:XData>
            </XmlDataProvider>
            <CollectionViewSource x:Key="animalsBySpecies" Source="{Binding Source={StaticResource data}, XPath=Animals/Animal}">
                <CollectionViewSource.GroupDescriptions>
                    <PropertyGroupDescription PropertyName="@Species" />
                </CollectionViewSource.GroupDescriptions>
            </CollectionViewSource>
        </Window.Resources>
        <DockPanel>
            <ScrollViewer DockPanel.Dock="Bottom" VerticalScrollBarVisibility="Auto">
                <ItemsControl ItemsSource="{Binding Source={StaticResource animalsBySpecies}}">
                    <ItemsControl.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.ContainerStyle>
                                <Style TargetType="{x:Type GroupItem}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                                <GroupBox  >
                                                    <GroupBox.Header>
                                                        <Grid>
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition></ColumnDefinition>
                                                                <ColumnDefinition></ColumnDefinition>
                                                            </Grid.ColumnDefinitions>
                                                            <TextBlock Text ="{Binding Name}" ></TextBlock>
                                                            <TextBlock Text="(" Grid.Column="1" Margin="15,0,0,0"></TextBlock>
                                                            <TextBlock Text="{Binding ItemCount}" Grid.Column="1" Margin="20,0,0,0"
                                                                       HorizontalAlignment="Right" ></TextBlock>
                                                            <TextBlock Text=")" Margin="0,0,-5,0" Grid.Column="1
                                                                                HorizontalAlignment="Right" ></TextBlock>
                                                        </Grid>
                                                    </GroupBox.Header>
                                                        <ItemsPresenter />
                                                </GroupBox>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </GroupStyle.ContainerStyle>
                        </GroupStyle>
                    </ItemsControl.GroupStyle>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding XPath=@name}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </DockPanel>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my WPF Application I have a canvas with a Listbox in it. I
I'm implementing a wpf application which display a list of items, and provides the
I'm considering either a ListBox or a ListView for a WPF application. It seems
In my WPF application I have 2 Windows (both Windows have their own ViewModel):
In my Composite WPF application I have an event that is published when the
In my WPF Application I have an GridViewColumn that looks like this: <GridViewColumn Width=170>
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
I have a datagrid in a WPF populated from a csv file. This is
This is probably mostly a question about how to use the VS 2010 IDE
First off let me just say I'm very new to coding so there are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.