Live Chat Icon For mobile
Live Chat Icon

How to get the default template of a control programmatically ?

Platform: WPF| Category: ControlTemplates

To get the Style for any given WPF control, get the control instance and use the ‘XAMLWriter’ class for writing the XAML related information.

[C#]

   System.Windows.Controls.TextBox t = new System.Windows.Controls.TextBox();
   StringBuilder sb = new StringBuilder();
   using (TextWriter writer = new StringWriter(sb))
   {
        System.Windows.Markup.XamlWriter.Save(t.Template, writer);
   } 

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.