开发者

How to grab WPF 4.0 control default templates? [duplicate]

This question already has answers here: 开发者_如何转开发 How to Extract Default Control Template In Visual Studio? (6 answers) Closed 4 years ago.

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.


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

How to grab WPF 4.0 control default templates? [duplicate]


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.

EDIT:

The .NET 4 Styles can be downloaded from here. More specifically, the Default WPF Themes link in the second paragraph. Alternatively, you can drill into specific controls to see a Style example.


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);


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.


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.


or install Expression Blend (trial) and go to below location:

C:\Program Files\Microsoft Expression\Blend 4\SystemThemes\Wpf
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜