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

  • Home
  • SEARCH
  • 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 672313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:28:17+00:00 2026-05-14T00:28:17+00:00

Is there a standard/best way to space items in a WPF ListBox , such

  • 0

Is there a standard/best way to space items in a WPF ListBox, such that there is space between consecutive items, but not above the first or below the last?

To me, the most obvious way to add spacing is to modify the ItemTemplate to include space above, below, or both above and below each item. This, of course, means that there will be space above/below the first and/or last item, too, or a single item.

I could use triggers to select different templates for first, last, intermediate items, but wonder if there is something simpler that I’m missing — seems that controlling spacing would be a common requirement.

Thanks.

NOTE: I am working in WPF, but assume this is similar if not identical in Silverlight XAML.

  • 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-14T00:28:17+00:00Added an answer on May 14, 2026 at 12:28 am

    What I would do is, Give negative margin on the ListBox control template, and give the same margin to the DataTemplate/ItemContainerStyle. which make the space in the first and last items. Check the below XAML. Instead setting in the DataTemplate I have given margin to the Button(ListBoxItem) itself.

       <Windows.Resources> 
         <ControlTemplate x:Key="ListBoxControlTemplate1" TargetType="{x:Type ListBox}">
            <Grid Background="{TemplateBinding Background}">
                <ItemsPresenter Margin="0,-5"/>
            </Grid>
           </ControlTemplate>
       </Window.Resources>
    
    
      <ListBox HorizontalAlignment="Center" VerticalAlignment="Center" Template="{DynamicResource ListBoxControlTemplate1}" Background="#FFAB0000">
            <Button Content="Button" Width="88" Margin="0,5"/>
            <Button Content="Button" Width="88" Margin="0,5"/>
            <Button Content="Button" Width="88" Margin="0,5"/>
            <Button Content="Button" Width="88" Margin="0,5"/>
            <Button Content="Button" Width="88" Margin="0,5"/>
        </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a standard or best-practices way to test that an action in rails
Is there a standard Java library that handles common file operations such as moving/copying
Is there a standard or common way in C++ to handle static strings that
In a large C++ solution, is there a best/standard way to separate the include
is there a standard or best practice with database table names and fields in
Is there a standard convention for the types of files that go in \Windows\
is there a standard way to encode the user location (country, state/region, town), so
Is there a standard way of maintaining a weak pointer to a parent (which
The standard specifies that the contents of reallocated space is undefined if the new
What's the best way to package Java software for running on Windows? Is there

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.