Where can i find the default WPF Control templates?

前端 未结 5 1101
萌比男神i
萌比男神i 2020-12-13 12:50

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 se

相关标签:
5条回答
  • 2020-12-13 13:03

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

    0 讨论(0)
  • 2020-12-13 13:07

    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(DataGridCell));
                using (XmlTextWriter writer = new XmlTextWriter(@"defaultTemplate.xml", System.Text.Encoding.UTF8))
                {
                    writer.Formatting = Formatting.Indented;
                    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.

    0 讨论(0)
  • 2020-12-13 13:17

    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.

    0 讨论(0)
  • 2020-12-13 13:19

    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
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题