通常,在哪里可以找到WPF DataGrid或WPF控件的XAML模板? [英] Where can I find the XAML template for a WPF DataGrid or a WPF control in general?

查看:81
本文介绍了通常,在哪里可以找到WPF DataGrid或WPF控件的XAML模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改 DataGrid (4.0版本)的控件模板,但是我不确定现有模板的外观。有人知道它是什么,或者在哪里可以找到它?

I would like to modify the control template for the DataGrid (4.0 version) but I am not sure what the existing template looks like. Does anyone know what it is or where I could find it?

通常:对于某些WPF控件,如何查看各自控件模板的默认内容?

In general: For some WPF control, how can I see the default content the respective control template?

推荐答案

我建议进入Blend(如果有)并提取模板。否则,您可以使用XAMLWriter获得XAML。

I would recommend going into Blend (if you have it) and extracting the Template. Otherwise, you can get the XAML using XAMLWriter.

不幸地命名了页面(我不认为这真的是孩子们的东西,对吗?)举了这两个例子。

This unfortunately named page (I don't think this is really "Kid's Stuff", do you?) has an example of doing both of these things.

如果页面确实消失了(2009年在后视镜中很远):

In case the page does happen to go away (2009 is pretty far in the rear-view mirror):

// Get the template from the control
YourControlType ctl = new YourControlType();
ctl.UpdateDefaultStyle();
ControlTemplate template = ctl.Template;

// We want our xaml of be properly indented, ohterwise
// we would not be able to indent them.
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Indent = true;

// Make the string builder
StringBuilder sb = new StringBuilder();
XmlWriter writer = XmlWriter.Create(sb, xmlSettings);
XamlWriter.Save(template, writer);


// Now the sb.ToString() should give us the template

全部归功于Shafqat Ahmed。

All credit to Shafqat Ahmed.

这篇关于通常,在哪里可以找到WPF DataGrid或WPF控件的XAML模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆