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 am new to WPF/XAML so please bear with the noob question. I have
In WPF C#, in code behind, I have to dynamically create an Array of
I have a WPF application that uses MVVM. Properties are databound to my viewModel.
I want to create custom WPF control that has a single child control inside.
I'm new to WPF, and created a 1st simplistic WPF application that I want
I am preparing for an exam and studying questions. However I have one question
I have a situation where I have someFunction(int) , and I need to generate
I've seen a lot of software that does something similar to what we need
I'm pretty new to WPF and implementing it via MVVM, and I'm trying to
we have a problem when trying to create events for a custom control in

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.