How to get existing control s ControlTemplate in WPF in XAML format (visual tree)? This is to help to create new ControlTemplate with the help of existing template.
但是,你也可以扩大现有的风格,而不通过使用<<>基于<><>>>的属性重新界定一切。
如果您有Expression Blend 你可以:
- Drag the control onto the design surface
- Right click the control and choose Edit Template -> Edit Copy
当你这样做时,Blend将从控制中抽取基础模板,并在文件/申请中明确宣布该模板是你可以用来支持你的灵魂的资源。 你们可以做任何控制。
由Matthew MacDonald撰写的《2008年C#》一书载有第15章中的“控制模板浏览器”。 我认为,你可以简单地从Apress网站下载样本代码。
<2020 Update:
All the styles and templates of WPF components are now moved here.
But, before creating a new component, just check this to see if you have a good alternative to that (maybe changing the style can work).
Note: Usually, it has a bunch of DynamicResource bindings that you might want to replace with yours and make static. If you don t want to do much manual work, you might consider using the second solution below.
第二种和较短的解决办法可能使用Microsoft Blend至extract 。 该模板包括以下步骤:
Right-click on the control >
Edit Template
>Edit Current
OREdit a pidt a
But be careful with this one, as it doesn t always export the whole template,
but the necessary part of it.
Just consider comparing this template with the official one (mentioned above) to make sure everything is fine.
http://www.sellsbrothers.com/tools/#ShowMeTheTemplate”rel=“nofollow noreferer” 缩略语
Use Microsoft Blend for it: Paste your entire XAML code in a file in this tool and right click the control whose visual tree you want to perceive:
Select the option: Edit template and there you go
The XamlWriter class provides you with this functionality. If controlName
is the Name of a Control
then using the below snippet you get the Xaml of the Control s Template inside the stringBuilder
object.
I guess tools mentioned in the answers utilize this class.
var stringBuilder = new StringBuilder();
var xmlSettings = new XmlWriterSettings
{
Indent = true
};
using (var xmlWriter = XmlWriter.Create(stringBuilder, xmlSettings))
{
XamlWriter.Save(controlName.Template, xmlWriter);
}
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding