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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:08:11+00:00 2026-05-28T08:08:11+00:00

I am using Buttons in Wpf C# application. I have declared a style for

  • 0

I am using Buttons in Wpf C# application.
I have declared a style for those buttons:

  <Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid Margin="0" Width="100" Height="60" >
                        //some more code here that sets color and stuff
                           <ContentPresenter HorizontalAlignment="Stretch" />
                            <Image  Source="Images/search_48.png" / >
                   //some more code here (triggers)
            </Setter.Value>
        </Setter>
    </Style>

I want this style to be applied to all buttons in my Window, but the image to be different.

I could have created many Styles by duplicating the code and setting each button a style of its own, while changing only the image, but I dont want this redundency.

I set the button style like this:

<Button x:Name="buttonName" 
        Style="{DynamicResource ButtonStyle}" 
        Content="button text">

As I mentioned, I have many buttons like this, and I want them all to have the same style but to change the image source in this style for each button.

Is there a way to do it without creating the same style with a different name for each button?

  • 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-28T08:08:11+00:00Added an answer on May 28, 2026 at 8:08 am

    Why don’t you just place the image inside the button instead of in the style.

    <Button x:Name="buttonName" Style="{DynamicResource ButtonStyle}" >
        <Image Source="Images/search_48.png" / >
    </Button>
    

    The Style would then look like this:

    <Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid Margin="0" Width="100" Height="60" >
                        //some more code here that sets color and stuff
                           <ContentPresenter HorizontalAlignment="Stretch" />
                   //some more code here (triggers)
            </Setter.Value>
        </Setter>
    </Style>
    

    UPDATE: If you have text and image use a stack panel:

    <Button x:Name="buttonName" Style="{DynamicResource ButtonStyle}" >
        <StackPanel Orientation="Horizontal">
            <Image Source="Images/search_48.png" Stretch="None" />
            <TextBlock>text</TextBlock>
        </StackPanel>
    </Button>
    

    Using the stack panel will allow you to either use vertical or horizontal orientation for your button layout. The text and image can then be positioned using margins inside the button.

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

Sidebar

Related Questions

I have a WPF app that is using the MVVM pattern. Hooking up buttons
I've deconstructed a standard WPF button using Blend and have managed to create a
I have a WPF Microsoft Surface Application and I'm using MVVM-Pattern. I have some
I have a wpf application that has a button for for each folder under
I am working on WPF application.I have bound my textblock to my button. I
In my WPF application, I have a main window (Branch.xaml) which has a button
What I have so far is: A WPF application, using MVVM, IDataErrorInfo implemented. Everything
I have a page where the user can edit various content using buttons and
I have some options for pricing using radio buttons. When a user selects the
I want to create some up and down buttons using the standard button background

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.