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 1061209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:26:37+00:00 2026-05-16T18:26:37+00:00

I have several ListBoxes and have set up the group style to make the

  • 0

I have several ListBoxes and have set up the group style to make the groups expanders. I want all of the ListBoxes to use the same style information to make them all expanders, but i want to be able to change the content of the header to be custom for each use of the style.

Is there any way i can take the out of the but still edit the contents of the

Currently, i am using a syntax similar to this:

<ListBox x:Name="listBox1" ItemsSource="{Binding}" Height="571" Width="260">

        <ListBox.GroupStyle>
            <GroupStyle>
                <GroupStyle.ContainerStyle>
                    <Style TargetType="{x:Type GroupItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type GroupItem}">
                                    <Expander IsExpanded="True" Style="{StaticResource GroupBoxExpander}">
                                        <Expander.Header>

                                            <Grid Width="190" Background="Yellow">

                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="40" />
                                                    <ColumnDefinition Width="40" />
                                                </Grid.ColumnDefinitions>

                                                <TextBlock Grid.Column="0" Text="Count:" />
                                                <TextBlock Grid.Column="1" Text="{Binding Path=ItemCount}" />

                                            </Grid>

                                        </Expander.Header>
                                        <Expander.Content>
                                            <ItemsPresenter Margin="15,0,0,0"></ItemsPresenter>
                                        </Expander.Content>
                                    </Expander>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </GroupStyle.ContainerStyle>
            </GroupStyle>
        </ListBox.GroupStyle>

        <ListBox.ItemTemplate>
            <DataTemplate>
                <local:ItemControl1 />
            </DataTemplate>
        </ListBox.ItemTemplate>

    </ListBox>

Any help greatly appreciated!

Thanks for reading

  • 1 1 Answer
  • 1 View
  • 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-16T18:26:37+00:00Added an answer on May 16, 2026 at 6:26 pm

    GroupItem is a ContentControl, so you could use the same Template with a different ContentTemplate. Separate your style out like this:

    <Style TargetType="{x:Type GroupItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}">
                    <Expander IsExpanded="True" >
                        <Expander.Header>
                            <ContentPresenter/>
                        </Expander.Header>
                        <Expander.Content>
                            <ItemsPresenter Margin="15,0,0,0"></ItemsPresenter>
                        </Expander.Content>
                    </Expander>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Grid Width="190" Background="Yellow">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="40" />
                            <ColumnDefinition Width="40" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Text="Count:" />
                        <TextBlock Grid.Column="1" Text="{Binding Path=ItemCount}"/>
                    </Grid>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    The ContentPresenter in the ControlTemplate will instantiate the DataTemplate, so this will have the same appearance, but you can customize the header by replacing the DataTemplate. You could create a base style with the ControlTemplate, and then create other styles based on that one that re-use the ControlTemplate but have a different DataTemplate.

    <Style TargetType="{x:Type GroupItem}"
           x:Key="BaseGroupStyle">
        <Setter Property="Template" .../>
    </Style>
    <Style TargetType="{x:Type GroupItem}"
           BasedOn="{StaticResource BaseGroupStyle}"
           x:Key="CountGroupStyle">
        <Setter Property="ContentTemplate" .../>
    </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'have several forms that use the same Listboxes. The ListBoxes are populated from a
I have several listboxes which have a SelectedItem property I intend to use as
I have several xml files with different node structure. I want to extract xml
I have several HTML elements (buttons) that fire the same JQuery AJAX request. When
I have several different numbers in a group that range in sizes and would
I have a workbook with several comboboxes (and listboxes) and a lot of vba
I have a ContextMenuStrip that is assigned to several different listboxes. I am trying
I have several listboxes that get each of their data from a separate stored
I have several circles on the screen, placed on different locations (all dynamic box2d
I have a situation where I have several listbox controls on the same asp.net

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.