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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:34:51+00:00 2026-05-24T08:34:51+00:00

We can make WPF Custom Control for overriding some control’s look&feel, like icon button.

  • 0

We can make WPF Custom Control for overriding some control’s look&feel, like icon button.

public class MyButton : Button {

    static MyButton()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(MyButton), new FrameworkPropertyMetadata(typeof(MyButton)));
    }
...
}

But I think that way has a some problem. It causes a some issue when I distribute the Custom Cotrol ‘MyButton’. Because MyButton dependent on external resource, the WPF Style MyButton. So I need to distribute two files : MyButton.cs and MyButton.WPF.

So, How can I definite a Conotrol Template by programmatically?

(Of cause, another way to solving the problem is making WPF User Control. but my point is not that.)

Note : I found some resources about this issue. That was a Inline XAML scripting. But to me, the XAML scripting is not option. Because I’m learning on WPF so I want to know WPF thatself, not a trick.

  • 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-24T08:34:52+00:00Added an answer on May 24, 2026 at 8:34 am

    You do not distribute the code, you distribute a dll that contains the class and the generic.xaml

    That way another designer/developer can ‘override’ the template and your template stays as a safe fall-back.

    EDIT

    Defining a Template in code is no fun (a lot of code, hard to debug, hard to maintain) but it can be done:

    var template = new ControlTemplate(typeof(MyControl));
    

    EDIT2

    Another hack is to specify the template in a long string and use the XAML Parser to load it.

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

Sidebar

Related Questions

I'd like to make some custom MenuHeaders in WPF so I can have (for
I have a WPF Custom Control inherited from Button. How do I programatically get
I know how to create a custom user control in WPF but how can
I am trying to make a custom control in WPF. I want it to
I am just wondering if I can make several button templates in WPF then
Now that I can make useful user controls in WPF (thanks to this stackoverflow
I have a complex WPF control that for some reasons (ie. performance) is not
I was wondering how I can make a GUI that looks like Media Center,
I can make a DAO recordset in VB6/Access do anything - add data, clean
I can make Firefox not display the ugly dotted focus outlines on links with

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.