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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:57:59+00:00 2026-06-09T11:57:59+00:00

I know this question is probably going to get alot of Duplicate question comments

  • 0

I know this question is probably going to get alot of “Duplicate question” comments but i have yet to see one with an answer that works or isn’t simply “Avoid it at all cost”. But here goes, i have created a control lets call it “ControlA” in a project called “ControlA_Project” and i was intending to override some of its virtual methods in a control called “ControlB” that inherites “ControlA” in another project called “ControlB_Project” . The idea being that “ControlA” has save and load methods that i wish to change from saving and loading to file, too saving and loading to database ( and if later on another save and load type is required i can just override those methods again ).
The problem i have is i originally had “ControlA” as a usercontrol and when i tried adding the new control with the overrides (“ControlB”) into a window i would get this error:

The component ‘ControlB_Project.ControlB’ does not have a resource identified by the URI ‘/ControlA_Project;component/usercontrols/ControlA.xaml’.

Googling the error i came to the conclusion you could not inherit from a user control ( or for the sake of arguement it wasn’t a good idea ). So i then changed the control from a user control to a custom control. this however then leads me to another problem, a template for a control doesnt link to the code behind (i.e On_Click) like it does in a user control and there is no easy way to simply override the behavier (as far as i am aware). I know i can retemplate ControlB by copy and pasting ControlAs template and changing a few lines but controlA has a large template as it is and making mutliple copies seems a waste of space.
So put simply is there a correct way to change the behavier of a control in wpf?

  • 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-06-09T11:58:00+00:00Added an answer on June 9, 2026 at 11:58 am

    First, remember that the ControlTemplate can be changed by the user alot so you need to make sure that important fields are clearly marked.
    So if you want an OnClick event. First mark your button as “important”

    <Button x:Name="PART_MyButton"/>
    

    Its also a good idea to mark this aswell on your control class

    [TemplatePart(Name = "PART_MyButton", Type = typeof(Button))]
    public class MyCustomControl : Control
    

    Now you want to attach to the on click event of that button to do that, override the OnApplyTemplate method.

    public override void OnApplyTemplate()
    {
        mButton = Template.FindName("PART_MyButton", this) as Button;
        mButton.Click += MyEventHandler;
    }
    

    Depending on how well your control can work without the control, you should gracefully handle a not found control or throw an exception.

    One final thing is. If you override a control which has a default style, it might be a good idea to provide a new default style.

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

    and placing an implicit style in your generic.xaml

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

Sidebar

Related Questions

I know this question is probably stoopid. But I just don't want to cause
I know this is probably a really amateur question, but I can't figure this
I know this is probably a very simple question but how would I do
This is one of those I probably should know this, but I don't questions.
Alright, I know questions like this have probably been asked dozens of times, but
This is probably going to be more of a discussion or hypothetical question, but
This is going to be a really dumb question, I just know it, but
I know that this question might have been asked like 100 times, but, believe
I think I already know the answer, but I'm going to ask the question
I don't know much about web development, so probably this question will sound exceptionally

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.