So what's the difference between Custom Control and User Control?

That's a good question came up after the series in my blog. Someone asked why should one use Custom Control instead of User Control? Hence, let's extend the series and discuss about that. I apologise the delay of this post. I should explain this at the start of the series, but actually my goal was to explain you how to create and use Custom Control in Silverlight.


It is better to do it later than never. Also, you are now familiar with Custom Control creation. Hence, start describing it. You will come to know more about this here. As always, don't forget to share your feedback at the end of this page.



If you came here through Search Engine result, I will recommend you to read my series of articles on Custom Control after reading this post. Those will help you to understand how to create a Custom Control in Silverlight.You can find the chapters here:

  1. How to create a Custom Control in Silverlight?
  2. How to design a Custom Control by editing the Part Template?
  3. How to implement Template Binding in Silverlight Custom Control?
  4. How to access Control Template parts from Code Behind?

Let's start describing difference between Custom Control and User Control.




What is Custom Control?

A custom control is a loosely coupled control defined in a class, which derives from Control. The UI of custom control generally defined in a Resource Dictionary inside the resource file. We can create themes for custom control and reuse them in various projects very easily.


Button, CheckBox, TextBox etc. even a UserControl is nothing but a Custom Control. You can easily load them inside a XAML page.




A Custom control generally inherits from System.Windows.Controls.Control class. You may derive from a different custom control also depending on your requirement.


Custom Controls are compiled into a dll assembly and can be reused in multiple places very easily. You have total control over it's code, thus gives you more flexibility to extend the behaviour. Once you build and add reference of custom control in your project, you can find it in the toolbox. Thus, you will be able to drag and drop the control in your design view and start working with that very easily.




What is User Control?

The base "UserControl" is nothing but a Custom Control that you derive to create control UI specific to your project. Generally we create a UserControl which placed inside a XAML page with tightly bonding to it's code behind. You can directly access it's UI elements from code behind and do some specific operations.




A custom UserControl inherits from System.Windows.Controls.UserControls class, which inherits from base "Control" class.


You can't create theming support for UserControls but can style them by creating theme for it's child Custom Controls because they represents a collection of controls. Once you create a UserControl UI in once project, you can't change them in the other projects.




Difference between CustomControl and UserControl

So, now you got the difference between Custom Control and User Control, I guess. Let's summarize the difference again. Read the comparison below to make it clear:


Custom Control User Control
A loosly coupled control w.r.t code and UI A tightly coupled control w.r.t code and UI
Derives from Control Derives from UserControl
Defines UI in the ResourceDictionary Defines UI as a normal XAML
UI can be skinable Child controls can skinable only
Has Dynamic layout Has static layout
UI can be changed in different project UI is fixed and can't have different look in every project
Has full toolbox support Can't be added to the toolbox
Defines a single control Defines a set of controls
More flexible Not much flexible like Custom Control
Requires in depth knowledge of Silverlight UI Model Does not require depth knowledge of UI Model


Hope, you got a better understanding now from the above comparison table.




When to use?

Good question "When to use a Custom Control?" Didn't you get the inner meaning of it yet? Ok, read the below summarized points:

  • When you have a rapid and fixed content in your UI, use UserControl.
  • When you want to separate some basic functionality of your main view to some smaller pieces with reusability, use UserControl for that.
  • When you want to use your control in different projects and each project may want to change the look according to their need, use CustomControl.
  • When you want to implement some additional functionality of a Control, create a CustomControl derived from the base control.
  • When you want to apply theme to your control, use CustomControl.
  • When you want to add toolbox support for your control, so that, your user will be able to do drag and drop to the designer, in such case, use CustomControl.



End Note

Hope, this information will help you to understand the difference between Custom Control and User Control. Also, it will help you to understand the use of each. Now, you will be able to decide where to use which one.


Appreciate your feedback and suggestion. Share this information to others. Follow me in Twitter @kunal2383. Also, follow my another Silverlight related news Blog: Silverlight-Zone.

If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter , Facebook , Google+ and LinkedIn . I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.


  1. I have a usercontrol show up just fine in my toolbox together with my custom controls, so thats perfectly possible.

  2. Thanks for such a useful explanation from which newbie silverlight developers who are not much aware of silverlight they can also learn easily about custom control and user control.

  3. Hi Kunal,

    Hats off to you man. Great article, great explanation. Looking forward for more insights.


  4. These posts came as a good tutorial for understanding and using custom controls. Thanks for sharing

  5. Its great when a developer is a good teacher. Thanks for the awesome post.

  6. Hi, thank you for good articles. Can you give an example how to get styles from generic.xaml in the different project. I have application project and class library with my Custom Control. In the application project I have usercontrol that uses my custom control. My problem is I cannot locate styles (generic.xaml) from library project. The only solution that I found is I need to create resource dictionary in the app.xaml like this:

    But it doesn't fit for my needs. I tried to declare resource dictionary directly in the UserControl.xaml, but in that case styles are not available, and I have exception in CustomControl.OnApplyTemplate method. I had similar to what you suggested, but structure is the same

    if (part_headerPanel == null || ....)
    // this exception
    throw new NullReferenceException("Template parts not available");

    Could you please shed some light on this issue.
    I use SL5.

    Thank you.

  7. For some reason code snippet disappeared from previous reply. This is it:

  8. Is there a difference between the layout process of two. When is IComponentConnector.COnnect called in the case of CustomControl.

  9. Hi Kunal, thanks for nice article, can you please help me in creating smooth line chart, you suggested to create a custom chart control by replacing the Polyline as PathGeometry, Can you please give some example for this, thanks in advance.


© 2008-2016 - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top