Manish Basantani
Manish Basantani

Reputation: 17499

Where can I find the default WPF Control templates?

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.

Upvotes: 52

Views: 30726

Answers (6)

user2019716
user2019716

Reputation: 643

For VS 2022 Community:

C:\Program Files\Microsoft Visual Studio\2022\Community\DesignTools\SystemThemes\

Upvotes: 4

John Stritenberger
John Stritenberger

Reputation: 1264

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.

Upvotes: 33

Amir Maleki
Amir Maleki

Reputation: 343

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.

Upvotes: 4

gehho
gehho

Reputation: 9238

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.

Upvotes: 22

McGarnagle
McGarnagle

Reputation: 102723

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

Upvotes: 15

Mike Nakis
Mike Nakis

Reputation: 61931

Long story short, this seems to be the link nowadays:

https://learn.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.)

Upvotes: 1

Related Questions