Where can i find the default WPF Control templates?
Solution 1
You can find the templates for all themes at Microsoft Docs.
Furthermore, there are several tools out there which can read the styles from an assembly.
For example, you could use Style Snooper.
However, for your scenario (getting the built-in templates), the above documentation link should be the easiest.
Solution 2
In Visual Studio 2015 (at least) you can right click the control in the XAML designer and select "Edit Style->Edit a Copy" to view and edit the default template for a control. Much easier than cracking open Blend, downloading a style viewer, or searching the web.
Solution 3
I arrived at this question via Google a few times, and could not see the link I wanted, so here it is...
- WPF styles and templates (These are not actually the defaults. I recommend avoiding these, and extracting them from Blend instead.)
- Silverlight styles and templates
These links have the following info for each framework control:
- Named template parts
- Visual states
- Full XAML default control template and resources
Solution 4
As this blog post says, use this code (call it once) and read the output file (defaultTemplate.xml):
public static void SaveDefaultTemplate()
{
var control = Application.Current.FindResource(typeof(ButtonSpinner));
using (XmlWriter writer = XmlWriter.Create(@"defaultTemplate.xml"))
{
XamlWriter.Save(control, writer);
}
}
In my opinion this is the best method.
Some elements like DataGridCell
are not extractable through Visual Studio tweak: Properties
>Template
>Convert to New Resource...
because you can't explicitly define any DataGridCell.
Solution 5
Long story short, this seems to be the link nowadays:
https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/button-styles-and-templates
(I copied the template for button from that page, and it does indeed seem to be the one.)
Related videos on Youtube
Manish Basantani
You can find me, and more details about me - and the work I do, at my blog: http://www.devdumps.com/about-me/ "Any fool can write a code that computer can understand. Good programmers write code that human can understand" ~ Martin Fowler
Updated on April 16, 2022Comments
-
Manish Basantani about 2 years
As per this MSDN link,
There is no way to replace only part of the visual tree of a control; to change the visual tree of a control you must set the Template property of the control to its new and complete ControlTemplate
.
I am trying to disable the click behaviour of GridViewColumnHeader ( I need to remove some triggers in the original control template), but i am not able to find the native "ColumnHeaderContainerStyle". All those i have found seem to have already done some customization and it is being difficult to get the original look and feel.
Can someone please suggest me how/where can i get the original control templates as defined in the native WPF controls?
Thanks for your interest.
-
Lukasz Madon over 13 yearsUse Reflector with Baml plugin to see xaml of default templates or maybe you can disable Grid behaviour in code?
-
Bonnev over 9 yearspossible duplicate of How/Where to Find Microsoft Default Styles for WPF Controls
-
stil over 8 yearspossible duplicate of Control template for existing controls in WPF
-
BrainSlugs83 about 4 yearsLooks like ILSpy can do this as well now too; as well as Expression Blend and Visual Studio are able to extract many of the built-in ones as well.
-
-
Sam over 13 yearsAlso Blend can extract the defaults.
-
Onur almost 9 yearsThe WPF link is broken
-
G.Y almost 9 yearsThese are just examples - they not reflect the default styles, they only cover most of it. you will notice the button has a blue'ish color which is not the default of a button in WPF.
-
Mathias Lykkegaard Lorenzen almost 8 yearsStyle Snooper link is no longer up to date.
-
Corin over 7 yearsIf you're looking for WPF, try this one: msdn.microsoft.com/en-us/library/aa970773(v=vs.110).aspx
-
Ties over 7 yearsAll these links don't really work anymore, but you can find the templates on your development box, under the Visual Studio directory (for me, it's:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\DesignTools\SystemThemes\Wpf\aero2.normalcolor.xaml
). -
peter70 about 7 yearsCorin, these are not standard values
-
lot about 7 yearsThis is da answer I was looking for. Place the control in visual xaml designer, right-click and go to "Edit Template-> Edit a copy..."
-
Lumo over 6 yearsThis does not work for me. Yes I get some "default", but it's not what I see on my Windows 10 machine !
-
Lumo over 6 yearsBTW: When I do it in Blend, I get the correct default template !
-
Rachel Martin over 5 yearsWhen you "Edit a Copy," it creates a copy of the current style. I simply commented out that style to use the default template before I selected "Edit a Copy".
-
BrainSlugs83 about 4 yearsLooks like the link is broken again (to clarify, the page loads, but selecting one of the controls to view the data takes you to a 404 page). -- @MikeNakis's answer below works.
-
BrainSlugs83 about 4 yearsConfirmed working as of the date of this comment. Thank you for posting this. 👍🏻