Search code examples
.netwpfdatatemplate

.NET 4 control default templates without Blend


How do people find the default templates of .NET controls when they can't use Expression Blend?

So far, when I needed the templates for WPF controls I went to the WPF project page on Codeplex, browsed the source code and usually found the default templates in "Generic.xaml" files.

But now I am looking for the default template for the "Frame" control. I can't find it on Codeplex, and I don't see it either in the .NET framework source provided by MS (XAML files are not provided, only .cs files).

The Style Snooper tool gives a default template but it seems reverse-engineered (unnecessary lengthy and referencing internal classes) rather than being the original clean definition.

So, how do poor people get those templates?


Solution

  • 1) you can get default template and seriallize it to file.

    var resource = Application.Current.FindResource(typeof(Control_Under_Interest));
    using (XmlTextWriter writer = new XmlTextWriter(file_name, System.Text.Encoding.UTF8))
    {
        writer.Formatting = Formatting.Indented;
        XamlWriter.Save(resource, writer);
    }
    

    2) Reflector with Baml Viewer may be used to get resources dictionaries from assemblies.

    3) dotPeek 1.1 supports BAML disassembling.