Where can i find the default WPF Control templates?

前端 未结 5 1109
萌比男神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: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.

提交回复
热议问题