views:

54

answers:

5

I have been using Expression Blend to copy the default templates for WPF 4.0 controls. I am writing a CodeProject article on extending WPF controls, and I would like to recommend a free tool as an alternative. What would you suggest? Thanks for your help.

A: 

MSDN lists them for Silverlight controls:
http://msdn.microsoft.com/en-us/library/cc278069(VS.95).aspx

But I can't find a similar listing for WPF controls. The corresponding WPF page is this and mysteriously absent a template listing:
http://msdn.microsoft.com/en-us/library/ms753328.aspx

Regardless, it's easy to grab the templates. From here:
http://msdn.microsoft.com/en-us/magazine/cc163497.aspx#S1

Control ctrl = GetControl(); // any type deriving from Control

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = new string(' ', 4);
settings.NewLineOnAttributes = true;
StringBuilder strbuild = new StringBuilder();
XmlWriter xmlwrite = XmlWriter.Create(strbuild, settings);

// Save the template to the XAML writer
XamlWriter.Save(ctrl.Template, xmlwrite);
Adam Sills
+4  A: 

XamlPadX has a button "Open/Close Styles Window" that shows little dialog which allows you to view the Styles.

alt text

karmicpuppet
Unfortunately, XamlPadX hasn't been updated for WPF 4.0. It doesn't have any of the new controls, such as the Calendar.
David Veeneman
A: 

Hi,

Please take a look at this article: http://eggheadcafe.com/tutorials/aspnet/d1ad0a33-d815-4083-8e97-c234fd661095/wpf-controls-default-style-or-template-by-extending-the-wpf-designer-in-visual-studio-2010.aspx. I've extended the WPF designer to include getting the default style or template through a context menu of the selected control. Just build the Visual Studio solution and set the registry entries to load the metadata. The downside is that XAML formatting is not like that of Expression Blend.

Michael Detras
Hi Michael--I took a look at your WPF calendar article for a project I'm working on. Nice job!
David Veeneman
Thanks, glad you like it.
Michael Detras
+1  A: 

In previous versions of WPF the styles were available at this MSDN link. You can try changing to Older versions, to see the download links. Unfortunately, this hasn't been updated for .NET 4.0 yet.

Until that happens, if ever you can use Reflector with the BamlViewer plugin. Once you have that installed, you'd open one of these assemblies using Open Cache:

  1. PresentationFramework.Aero
  2. PresentationFramework.Classic
  3. PresentationFramework.Luna
  4. PresentationFramework.Royale

Make sure to select the 4.0.0.0 versions. Then expand the assembly and associated Resources nodes. Selected the resource entry and press the Space bar to view the Disassembler. Then you can see the BAML files, which you can view the XAML using BamlViewer. The only downside is you lose the original formatting.

Tom Goff
A: 

Control templates for WPF 4.0 controls can now be found here.

However, You can extend or override a control template without having to reproduce the original, by using the Style.BasedOn property. It is explained in this blog post.

David Veeneman