ControlTemplate for existing controls in WPF

Viewed 24164

How to get existing control's ControlTemplate in WPF in XAML format (visual tree)? This is to help to create new ControlTemplate with the help of existing template.

8 Answers

The book "Pro WPF in C# 2008", by Matthew MacDonald, includes a Control Template browser in Chapter 15. I believe you can simply download the sample code from the Apress web site.

2020 Update:

All the styles and templates of WPF components are now moved here.
But, before creating a new component, just check this to see if you have a good alternative to that (maybe changing the style can work).
Note: Usually, it has a bunch of DynamicResource bindings that you might want to replace with yours and make static. If you don't want to do much manual work, you might consider using the second solution below.

The second and shorter solution might be using Microsoft Blend to extract the template with the following steps:

Right-click on the control > Edit Template> Edit Current OR Edit a Copy

But be careful with this one, as it doesn't always export the whole template,
but the necessary part of it.
Just consider comparing this template with the official one (mentioned above) to make sure everything is fine.

Related