WPF Composite Controls – Custom Controls


WPF provides enormous infrastructure to create custom controls or composite controls. There are two ways with which this can be achieved.

1. Extend UserControl and add other controls to it called as constituent controls. These constituent controls are given private access hence not accessible to other assemblies.

2. Create custom control by extending Control or ContentControl class. This way you can define your own functionality and appearance.

Extending UserControl class provides IDE design interface where you can drag and drop other controls. This is the only main difference between composite and custom control as templates gives use powerful mechanism to change functionality as well as appearance.

In both ways you have to add DependancyProperties to your control to take advantage of WPF data binding infrastructure. Now question arises when to choose UserControl, CustomControl or Template based customization.

This decision is based on functionality rather than appearance. If current control provides all the functionality then create template to change the appearance of the control. If the functionality can be provided by combining pre existing controls and some code then create UserControl. If these both cases do not satisfy the functionality then create custom control in WPF.


Leave a Reply

Your email address will not be published. Required fields are marked *