关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。
想改进这个问题?将问题更新为 on-topic对于堆栈溢出。
3年前关闭。
Improve this question
我想修改 DataGrid
的控制模板(4.0 版),但我不确定现有模板是什么样的。有谁知道它是什么或我在哪里可以找到它?
总的来说:对于一些WPF控件,如何查看各自控件模板的默认内容?
最佳答案
我建议进入 Blend(如果你有的话)并提取模板。否则,您可以使用 XAMLWriter 获取 XAML。
这个unfortunately named page (我不认为这真的是“ child 的东西”,对吗?)有一个做这两件事的例子。
如果页面碰巧消失了(2009 年在后视镜中很远):
// 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。
关于wpf - 一般而言,我在哪里可以找到 WPF DataGrid 或 WPF 控件的 XAML 模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4165848/