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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:08:08+00:00 2026-05-22T20:08:08+00:00

I have a WPF that creates buttons dynamically when the form is loaded and

  • 0

I have a WPF that creates buttons dynamically when the form is loaded and adds them to a StackPanel that has been declared in XAML. I would like to define the style for these buttons completely in XAML inside the StackPanel.Resources. So far I am able to do this for Style properties just fine, but what I am having trouble figuring out is the best way to do the margin. I know that Margin is a Thickness and cannot actually be applied in a style, but must be defined as a static resource and applied directly to the Margin property. Is there a way I can do this in XAML without resorting to the code-behind?

Here is the XAML for my StackPanel:

        <StackPanel
            x:Name="_dialogButtons"
            Orientation="Horizontal"
            HorizontalAlignment="Right"
            DockPanel.Dock="Right">

            <StackPanel.Resources>
                <Style
                    TargetType="{x:Type Button}">
                    <Setter
                        Property="MinWidth"
                        Value="75" />
                    <Setter
                        Property="Padding"
                        Value="3" />
                </Style>                    
            </StackPanel.Resources>

        </StackPanel>

Thanks,

Mike

  • 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-22T20:08:09+00:00Added an answer on May 22, 2026 at 8:08 pm

    You state that “I know that Margin is a Thickness and cannot actually be applied in a style”, this is not correct. Margins can be applied in XAML, the Thickness type has a type converter that can convert a string to a Thickness allowing you to define it as follows:

    <setter Property="Margin" Value="5,5,5,5"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF TabControl that has a couple of buttons in the TabItem
We have a WPF Application that has a two flavors with a consistent UI
I have a WPF page that has 2 ContentControls on it. Both of the
I have a VB.net WPF application that creates a list from a databind. For
I created a WPF application that has many buttons. Now the customer wants to
I am using Buttons in Wpf C# application. I have declared a style for
I have created styled a ListBox in WPF so that it is rendered as
I have a WPF application where I'd like to create a custom pop-up that
I have WPF Span that is used as a source to a TextBlock. I
I have a WPF ListView that is bound to a BindingList<T>. The binding works

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.