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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:33:31+00:00 2026-05-15T08:33:31+00:00

i narrowed down what i want my wpf button to look like using XAML.

  • 0

i narrowed down what i want my wpf button to look like using XAML.

now i would like to create a sub classed button control that i can just re-use w/out having to write all that markup

<Button Click="TestGridColumnButton_Click" Background="Transparent" Width="16" Height="16" Margin="0,0,0,0" Padding="0,0,0,0" BorderBrush="{x:Null}">
    <Button.Template>
        <ControlTemplate>
            <Image HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource SourceStyle}" />
        </ControlTemplate>
    </Button.Template>
</Button>

how can i set all these properties using C# ?

  • 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-15T08:33:31+00:00Added an answer on May 15, 2026 at 8:33 am

    There are multiple ways to do that :

    [Note: For the sake of this answer, I assume you are creating a button in a simple window.]

    1) A not-reusable and kind of dirty way would be to assign all the properties in the window’s loaded event. By naming the button object, you can get reference to it and assign values to the properties, register to the event and assign a template. I assume you were having trouble with the template properties. To create a template in code, you can either use FrameworkElementFactory class (which is deprecated) or use XamlReader.Load method.(which is the preferred approach).

    2) Create a custom control, for which a custom template is created in generic.xaml file. You can name elements in the custom template and retrieve references to them by overriding OnApplyTemplate method. Then you can create public properties which directly map to the Image element in the template or expose the Image element as a public property in the control. Using this approach, you can set properties in C# code using your exposed properties.

    3) You can also define multiple styles and toggle between them in c# code. This method works just like in HTML when we toggle classes using JavaScript.

    Hope this helps!

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

Sidebar

Related Questions

I've been investigating this problem for several hours now and narrowed it down to
My friend and I want to write a Facebook application. We've narrowed down the
NARROWED DOWN SOLUTION I'm much closer, but don't know how to apply XAML to
I have narrowed down my problem to the mysql_connect call I am doing in
I have narrowed down my issue to a derived classes copy constructor, but I
I've narrowed down in my application that my AVI video player is leaking memory.
I was having an odd problem that I narrowed down to the following test
I have some rather odd behavior in my D program that I've narrowed down
With Java and Perl background, I have narrowed down the web framework choices to
I've done my research and narrowed this down. OK, so I am deciding on

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.