ISerialized .Net, C#, Scrum and agile software development

27Jan/101

Why use Custom Control instead of User Control in WPF?

When I first started experimenting with WPF I was quite confused with the new custom control introduced in WPF. I did a quick Google search but never got the full understanding of the difference, but I read somewhere that in most cases a custom control was not necessary, so I just focused on the regular user control back then.

That was a couple of months back, and I still only use regular user controls. I see however that for my use, the regular user control is enough! When adding a custom control, you will automatically get a resource file with xaml (Generic.xaml) defining the styles of the custom controls, hence adding the possibility for easy theming. And I guess this is one of the main benefits of the custom control, namely to enhance existing user controls, and giving the consumer the possibility to use theming, eg. when developing controls for third party use.

Custom Control

  • Used when enhancing an existing control with new features
  • Supports theming for consumers.
  • WPF has a very good support for theming giving you the ability to customize the control to what every style you want, eg. when added/used in third party libraries.
  • Only a cs file
  • Style kept in Generic.xaml

User Control

  • The user control won't support theming by consumers
  • The developer of the user control have full styling possibilities (of course)
  • Used when composing it for your own consumption
  • Used when you know third party theming is not an option.
  • Derives from UserControl

Later I will post an code walk through on how to create and consume a custom control in WPF. 

Posted by Pål Eie

Comments (1) Trackbacks (0)
  1. Now that its been a bit longer do you have any updates to this?


Leave a comment

No trackbacks yet.