Charles Petzold



Article on Custom Controls and Templates

December 26, 2007
Roscoe, N.Y.

The January 2008 issue of MSDN Magazine is now online, including my article Templates for Uncommon Controls.

Creating a WPF custom control is fairly easy: Just derive from UserControl and define the control's visual tree as the Content property.

Creating a new template for an existing control is also fairly easy: Just replace the Template property with a custom visual tree.

However, as I discovered while writing this article, creating a custom control with a replaceable template is not so easy. In theory, all you need to do is derive from Control and define a default Template property. It turns out there are special requirements if you want to put this custom control in a DLL (as you probably do) and there are several standard techniques for making the template accessible from the control's code.

If you want to create custom controls and allow other programmers to replace the control's template with one of their own design, this article is for you.