Extract WPF content template to run WPF application

Is there a way to retrieve the content template of a WPF control that is hosted in a running WPF application?

Just as I can delve into the visual tree of any WPF application using tools like Snoop, I would like to get a content template.

I already asked Google. But either my keywords were completely wrong, or there could be no solution (which I doubt).

Can someone give me a hint?

thank

+3
source share
3 answers

What do you think of this little extension method?

using XamlWriter = System.Windows.Markup.XamlWriter;
public static class FrameworkTemplateExtensions
{
    /// <summary>
    /// Returns properly-indented XAML representing the given template.
    /// </summary>
    public static string AsXaml(this FrameworkTemplate template)
    {
        if (template == null)
        {
            return null;
        }
        XmlWriterSettings xmlSettings = new XmlWriterSettings();
        xmlSettings.Indent = true;
        StringBuilder builder = new StringBuilder();
        using (XmlWriter writer = XmlWriter.Create(builder, xmlSettings))
        {
            XamlWriter.Save(template, writer);
        }
        return builder.ToString();
    }
}
+1
source

Xaml, Binary Xaml (Baml), , , Xaml, .

0

This tool allows you to view the current WPF tree. Until you debug the application using VS at the same time.

http://snoopwpf.codeplex.com/

0
source

Source: https://habr.com/ru/post/1766854/


All Articles