Obtain the built-in control template (XAML) and wpfxaml in WPF.

Source: Internet
Author: User

Obtain the built-in control template (XAML) and wpfxaml in WPF.

Each control has its own default template, which is compiled by MS itself. If we can get the XAML code of these templates, it will be the best example of learning templates, to obtain the default template of a control ctrl, call the following method:

 1         string GetTemplateXamlCode(Control ctrl) 2         { 3  4             FrameworkTemplate template = ctrl.Template; 5  6             string xaml = ""; 7  8             if (template != null) 9             {10 11                 XmlWriterSettings settings = new XmlWriterSettings();12                 settings.Indent = true;13                 settings.IndentChars = new string(' ', 4);14                 settings.NewLineOnAttributes = true;15 16                 StringBuilder strbuild = new StringBuilder();17                 XmlWriter xmlwrite = XmlWriter.Create(strbuild, settings);18 19                 try20                 {21                     XamlWriter.Save(template, xmlwrite);22                     xaml = strbuild.ToString();23                 }24                 catch (Exception exc)25                 {26                     xaml = exc.Message;27                 }28             }29             else30             {31                 xaml = "no template";32             }33 34             return xaml;35         }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.