Where can i find the default WPF Control templates?

26,656

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...


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.)

Share:
26,656

Related videos on Youtube

Manish Basantani
Author by

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, 2022

Comments

  • Manish Basantani
    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.

  • Sam
    Sam over 13 years
    Also Blend can extract the defaults.
  • Onur
    Onur almost 9 years
    The WPF link is broken
  • G.Y
    G.Y almost 9 years
    These 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
    Mathias Lykkegaard Lorenzen almost 8 years
    Style Snooper link is no longer up to date.
  • Corin
    Corin over 7 years
    If you're looking for WPF, try this one: msdn.microsoft.com/en-us/library/aa970773(v=vs.110).aspx
  • Ties
    Ties over 7 years
    All 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
    peter70 about 7 years
    Corin, these are not standard values
  • lot
    lot about 7 years
    This 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
    Lumo over 6 years
    This does not work for me. Yes I get some "default", but it's not what I see on my Windows 10 machine !
  • Lumo
    Lumo over 6 years
    BTW: When I do it in Blend, I get the correct default template !
  • Rachel Martin
    Rachel Martin over 5 years
    When 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
    BrainSlugs83 about 4 years
    Looks 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
    BrainSlugs83 about 4 years
    Confirmed working as of the date of this comment. Thank you for posting this. 👍🏻