51

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.

Manish Basantani
  • 16,931
  • 22
  • 71
  • 103
  • Use Reflector with Baml plugin to see xaml of default templates or maybe you can disable Grid behaviour in code? – Lukasz Madon Aug 23 '10 at 14:28
  • possible duplicate of [How/Where to Find Microsoft Default Styles for WPF Controls](http://stackoverflow.com/questions/9068830/how-where-to-find-microsoft-default-styles-for-wpf-controls) – Bonnev Nov 22 '14 at 20:05
  • possible duplicate of [Control template for existing controls in WPF](http://stackoverflow.com/questions/1559261/control-template-for-existing-controls-in-wpf) – stil Sep 08 '15 at 11:34
  • Looks 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. – BrainSlugs83 Apr 23 '20 at 09:39

6 Answers6

31

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.

John Stritenberger
  • 1,194
  • 1
  • 12
  • 30
  • 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..." – lot Mar 29 '17 at 21:33
  • 1
    This does not work for me. Yes I get some "default", but it's not what I see on my Windows 10 machine ! – Lumo Sep 08 '17 at 10:26
  • BTW: When I do it in Blend, I get the correct default template ! – Lumo Sep 08 '17 at 10:32
  • 1
    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". – Rachel Martin Nov 14 '18 at 15:10
21

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.

devpelux
  • 2,492
  • 3
  • 18
  • 38
gehho
  • 9,049
  • 3
  • 45
  • 59
15

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
devpelux
  • 2,492
  • 3
  • 18
  • 38
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
  • 3
    The WPF link is broken – Onur Jul 01 '15 at 07:57
  • 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. – G.Y Jul 15 '15 at 02:49
  • 3
    If you're looking for WPF, try this one: https://msdn.microsoft.com/en-us/library/aa970773(v=vs.110).aspx – Corin Jan 19 '17 at 00:20
  • 1
    Corin, these are not standard values – peter70 Feb 10 '17 at 15:41
  • 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 Apr 23 '20 at 09:45
3

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

user2019716
  • 587
  • 4
  • 13
2

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.

Amir Maleki
  • 313
  • 1
  • 11
1

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

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142