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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:52:56+00:00 2026-05-25T01:52:56+00:00

I am using listbox grouping, I want to avoid vertical spaces left between header

  • 0

I am using listbox grouping, I want to avoid vertical spaces left between header and subelements, as shown below:

enter image description here

Here is the xaml for the same

<Grid>
    <Grid.Resources>
        <XmlDataProvider x:Key="Company" XPath="/Company">
            <x:XData>
                <Company xmlns="">
                    <Person Name="Jack" Role="CEO"/>
                    <Person Name="Tim" Role="PL" />
                    <Person Name="Jil" Role="PL" />
                    <Person Name="Jimmy" Role="PM" />
                    <Person Name="Joy" Role="PM" />
                    <Person Name="Jim" Role="PL" />
                    <Person Name="Jack" Role="PM" />
                </Company>
            </x:XData>
        </XmlDataProvider>

        <DataTemplate x:Key="categoryTemplate">
            <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Background="ForestGreen" Margin="0,5,0,0"/>
        </DataTemplate>
        <DataTemplate x:Key="template">
            <TextBlock Text="{Binding XPath=@Name}"/>
        </DataTemplate>

        <CollectionViewSource x:Key="cvs" Source="{Binding Source={StaticResource Company},XPath=Person}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="@Role"/>
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    </Grid.Resources>


    <ListBox Name="lst" ItemTemplate="{StaticResource template}" ItemsSource="{Binding Source={StaticResource cvs}}">
        <ListBox.GroupStyle>
            <GroupStyle HeaderTemplate="{StaticResource categoryTemplate}" />
        </ListBox.GroupStyle>
    </ListBox>
</Grid>
  • 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-25T01:52:57+00:00Added an answer on May 25, 2026 at 1:52 am

    The ListBox will use GroupItems when you group and they have a default Margin set to 5,0,0,0. Also, ListBoxItem comes with a default Padding of 2,0,0,0. You can change either one, or both, of them like this

    <ListBox ...>
        <ListBox.Resources>
            <Style TargetType="{x:Type GroupItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GroupItem}">
                            <StackPanel>
                                <ContentPresenter/>
                                <ItemsPresenter Margin="0,0,0,0"/>
                            </StackPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ListBox.Resources>
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="Padding" Value="0"/>
            </Style>
        </ListBox.ItemContainerStyle>
        <!--...-->
    </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a controlTemplate of the ListBox to show a collection. I want to
I am using a ListBox with a DataTemplate to create the below map legend.
I am using the below code to find all the items in a listbox
I'm trying to bind a collection to a ListBox using only XAML. It kind
i'm using a listbox style twice in my project so i want to use
I'm using a ListBox in WPF, and I want to enable/disable a button only
I display the contents of a table in the database using a ListBox. Each
How do you programmatically select items in a multi-select listbox using jQuery?
is there a way to unselect all items of a listbox using jquery without
When I use the following code it works because I am using a ListBox

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.