WPF has two concepts of controls: UserControls and CustomControls. But what's the difference between them? In this article I try to list the characteristics of each of them to help you to choose the right type for your project.
UserControl (Composition)
- Composes multiple existing controls into a reusable "group"
- Consists of a XAML and a code behind file
- Cannot be styled/templated
- Derives from UserControl
Color
DependencyProperty that gets and sets the resolved color.CustomControl (Extending an existing control)
- Extends an existing control with additional features
- Consists of a code file and a default style in
Themes/Generic.xaml
- Can be styled/templated
- The best approach to build a control library
OnApplyTemplate()
override in the logic part of the control. The ControlTemplate can easily be exchanged by another that has the up,down buttons aligned left for example.
No comments:
Post a Comment