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
Check out StyleSnooper:
It will dump out the standard styles (and therefore templates too) for the built in controls. You can also load in a specific DLL that contains WPF controls and view the default styles for those too.

- 300,895
- 165
- 679
- 742
-
@doron-yaacoby, I have found another link to download from: http://blog.tomaskafka.com/book/export/html/112 – Nicolai Shestakov Aug 20 '14 at 10:37
-
@NicolaiShestakov, thanks, I've updated the link in the answer. – Drew Noakes Aug 20 '14 at 13:55
-
@Glorfindel, you're doing great work with these edits! I've seen several from you now. Thanks! – Drew Noakes May 03 '19 at 03:31
-
1I would like to add what is probably the newest link: https://github.com/drewnoakes/style-snooper – Xam Jun 24 '20 at 04:19
The styles along with template examples are up on MSDN for download, see the Default WPF Themes
link.
However you can also extend the existing style without redefining everything by using the BasedOn
attribute.

- 39,066
- 20
- 121
- 167
If you have Expression Blend you can:
- Drag the control onto the design surface
- Right click the control and choose Edit Template -> Edit Copy
When you do this, Blend will extract the base template from the control and explicitly declare it within document/application as a resource which you can then edit to your liking. You can do this for any control.

- 33,111
- 3
- 82
- 100
-
I think this answer should get more attention, it is probably the best way to do this. – Jul 04 '21 at 19:07
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.

- 18,912
- 32
- 122
- 187
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
OREdit 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.

- 10,860
- 6
- 57
- 75
You can use a tool like ShowMeTheTemplate

- 286,951
- 70
- 623
- 758
-
Is there a code to get it in XAML format?(like view the visual tree in tree format) – Oct 13 '09 at 10:15
-
yes, since this tool does it... you can look at the code, it's provided in the zip file – Thomas Levesque Oct 13 '09 at 10:31
Use Microsoft Blend for it: Paste your entire XAML code in a file in this tool and right click the control whose visual tree you want to perceive:
Select the option: Edit template and there you go

- 619
- 3
- 10
The XamlWriter class provides you with this functionality. If controlName
is the Name of a Control
then using the below snippet you get the Xaml of the Control's Template inside the stringBuilder
object.
I guess tools mentioned in the answers utilize this class.
var stringBuilder = new StringBuilder();
var xmlSettings = new XmlWriterSettings
{
Indent = true
};
using (var xmlWriter = XmlWriter.Create(stringBuilder, xmlSettings))
{
XamlWriter.Save(controlName.Template, xmlWriter);
}

- 3,505
- 3
- 18
- 16