While designing anew window, WPF architecture, I needed a NumericUpDown Control. Since the current SDK is missing this control I have found myself asking the question…
CustomControl or UserControl?
So, what is the main difference and what should we use?!
UserControl: Provides a simple way to create a control.
CustomControl: Represents the base class for user interface (UI) elements that use a ControlTemplate to define their appearance.
So, now we can see that the main difference between them is that the CustomControl basically build by using the ControlTemplate.
The big and the major advantage that we have during XAML design (and this is true to both control types) is that we can change the style of an existing control while the logic functionality remain as it is. Change the style, Not the logic!!! Still, what is the difference ???
The big issue here is how easy we can change the style!!!
If there is something that I don’t like is to change all the control or try to find it’s inner controls to change it. For example if we have a ComboBox and I want to change the Path of the triangle on the button, I want an easy way to do so. Today we can use the Expression Blend ability to auto extract and edit the control style.
When you creation a UserControl by auto generated <Style> it abstract and give us the main layer and noting beside that
For example – The <Style> will look like similar to that:
We have nothing to start with!!!
On the Other hand the CustomControl is based on the ControlTemplate and therefore, also the auto generated tool can base on it and the <Style> will be more detailed. So the change that we would like to do can be more specific.
if you need an atomic control and the ability to change the style in the future, we should use the CustomControl (don’t forget to override OnApplyTemplate() method). If the control is more complex just create a UserControl and hope that his style is final and no change should be done later.