wpf - 一般而言,我在哪里可以找到 WPF DataGrid 或 WPF 控件的 XAML 模板?

标签 wpf templates xaml datagrid

关闭。这个问题不符合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/

相关文章:

c# - 如何在本地网络的一台计算机上运行业务逻辑,在另一台计算机上运行GUI?

wpf - 绑定(bind)的好处?

c++ - 基本类型的 std::vector 的部分类模板特化

wpf - DataGrid RowStyle - DataTrigger 中的绑定(bind)值

c# - 自动适应列表框子项的宽度

c++ - 仅更改 C++ 模板中类型的一部分

带有验证错误样式的 WPF 数据网格单元

c# - 如何使用 Syncfusion Metro Studio 生成的 XAML 字典

C# WPF 代码在 Visual Studio 中的运行速度比在控制台中的运行速度快,而在另一个文件夹中的运行速度较慢

C++ - 如何为类模板声明函数模板友元