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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:43:16+00:00 2026-05-10T19:43:16+00:00

If I have a usercontrol (in Silverlight) that I’ve written, that uses XAML to

  • 0

If I have a usercontrol (in Silverlight) that I’ve written, that uses XAML to define it’s appearance, how can I make a customised version of it?

i.e. I have MyControl.xaml & MyControl.xaml.cs

What do I need to do if I want a ‘SpecialisedControl’ child class? I assume I just make a new code file, then inherit from MyControl. But what if I want to change the appearance of the base class – then what do I do?

  • 1 1 Answer
  • 2 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. 2026-05-10T19:43:16+00:00Added an answer on May 10, 2026 at 7:43 pm

    I wrote this thinking you were talking about WPF, rather than Silverlight, but there may be enough overlap for this to be helpful, so I’m posting it, anyway.

    If by ‘change the appearance of the base class’ you mean ‘provide a new template’, then what you need is probably a CustomControl, not a UserControl.

    The best way to accomplish this is to follow the example set by other Microsoft controls, such as Button or ListBox:

    1. Create a class that derives directly from Control (or whatever is closest to your control).
    2. If any properties will need to be exposed to the control (such as text on a button, for example), make sure that you properly define them as DependencyProperties.
    3. As described here, create a ResourceDictionary called Themes/generic.xaml and add a style for your class that includes a template (don’t give the style a key).
    4. Use TemplateBindings for any properties of elements on your control that need to get values from your control.
    5. If you’ll need to attach any event handlers to elements in your template, give them a unique name. Microsoft uses the convention of prefixing these names with ‘PART_’, and I think it’s a good thing to do for the sake of consistency, but it’s not strictly required.
    6. Again, if you need to attach event handlers, overload OnApplyTemplate(). In this method, you should detach any old event handlers (we certainly don’t want any memory leaks!), and look for elements that have the names your provided in your template–when you find them, attach event handlers, as necessary.

    This is certainly much more work than simply deriving from UserControl, but if you want to be able to totally re-template controls, like you can with the built-in controls, this is the way to do it.

    On the other hand, if all you want to do is to provide a certain amount of limited customization, such as changing the background, or associating a Command with some user action, then the best thing to do is to expose DependencyProperties, which can then be set in styles for your control, or on instances of your control, itself.

    In the case you mentioned of wanting to customize the look in an inherited control, the process is pretty similar: just add a default style for the new control with a new template; if you need to add more event handlers, just be absolutely certain that you call base.OnApplyTemplate().

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

Sidebar

Related Questions

I have a silverlight application that uses WCF, and I would like to make
I have a Silverlight XAML usercontrol that I want to use to show that
I have the following (condensed) silverlight xaml for a view / viewmodel: <UserControl x:Class=MyView>
I have a Silverlight UserControl which uses the ContentPropertyAttribute to exposes the Children property
I have an usercontrol in silverlight that I'm trying to convert to custom control.
I have a custom base user control in silverlight. <UserControl x:Class=Problemo.MyBaseControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008
I have an UserControl that contains a Button : <UserControl> <Button> </UserControl> I want
I have an MVVM Silverlight 4 application that holds a list of modules (a
I have read that we can not access anything in the main UI thread
In my Silverlight app I have UserControl and I want to reference a StaticResource

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.