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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:49:47+00:00 2026-06-09T03:49:47+00:00

If I have a Horizontal StackPanel with many elements, with different margin between them:

  • 0

If I have a Horizontal StackPanel with many elements, with different margin between them:

Is there any difference if I give each element a left margin or
is there some advantage giving every second element a right and left margin – that way only one element gets its margin property set.

<StackPanel Orientation="Horizontal">
<TextBlock Name="textblock1" />
<TextBlock Name="textblock2" Margin="5,0,0,0" />
<TextBlock Name="textblock3" Margin="10,0,0,0" />
...
</StackPanel>

or

<StackPanel Orientation="Horizontal">
<TextBlock Name="textblock1" />
<TextBlock Name="textblock2" Margin="5,0,10,0" />
<TextBlock Name="textblock3" />
...
</StackPanel>

I was just wondering if there was a best-practise concerning this.

  • 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-06-09T03:49:49+00:00Added an answer on June 9, 2026 at 3:49 am

    If the Margin is the same for every element, you can factor it out in a style:

    <StackPanel Orientation="Horizontal">
       <StackPanel.Resources>
          <Style TargetType="TextBlock>
             <Setter Property="Margin" Value="5,0,0,0" />
          </Style>
       </StackPanel.Resources>
       <TextBlock Name="textblock1" />
       <TextBlock Name="textblock2" />
       <TextBlock Name="textblock3" />
       ...
    </StackPanel>
    

    Other than that it makes no difference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following ItemTemplate: <ItemsControl ItemsSource={Binding Topics}> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal Margin=10,0> <TextBlock
i have customized ListBox declared in XAML: <ListBox x:Name=uicMDSQonfServer> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal Margin=0,5,0,5>
I have a textblock inside a vertical stackpanel inside a horizontal stackpanel (think Facebook
Do you know any controls inherited from the ItemsControl that have horizontal orientation of
Please, let's focus on the horizontal size (width). I have horizontal StackPanel which auto-resizes
I have a horizontal StackPanel with an image and another StackPanel. The inner StackPanel
I have wpf user control <StackPanel Orientation=Horizontal> <TextBox Name=txbInterval Text=5/> <Image Name=imgStart Source=Images/start.png/> <Image
I have the following XAML: <StackPanel> <StackPanel Orientation=Horizontal> <Border Name=B1 Width=Auto> <DataGrid /> </Border>
I have the following XAML: <DockPanel x:Name=OverViewContainer AllowDrop=True> <StackPanel Orientation=Horizontal DockPanel.Dock=Bottom HorizontalAlignment=Right> <uicommon:Toolbar DataContext={Binding
OK, I give up: what do I have to change to this StackPanel below

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.