在哪里可以找到默认的 WPF 控件模板?
根据此 MSDN 链接,
没有办法只替换部分 控件的可视化树;到 更改控件的可视化树 您必须设置 Template 属性 控制到新的和完整的 控制模板。
我试图禁用 GridViewColumnHeader 的点击行为(我需要删除原始控件模板中的一些触发器),但我无法找到本机 ColumnHeaderContainerStyle 。我发现的所有这些似乎都已经做了一些定制,很难获得原始的外观和感觉。
有人可以建议我如何/在哪里可以获得本机 WPF 控件中定义的原始控件模板吗?
感谢您的关注。
As per this MSDN link,
There is no way to replace only part
of the visual tree of a control; to
change the visual tree of a control
you must set the Template property of
the control to its new and complete
ControlTemplate.
I am trying to disable the click behaviour of GridViewColumnHeader
( I need to remove some triggers in the original control template), but I am not able to find the native ColumnHeaderContainerStyle
. All those I have found seem to have already done some customization and it is being difficult to get the original look and feel.
Can someone please suggest me how/where can I get the original control templates as defined in the native WPF controls?
Thanks for your interest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在 Visual Studio 2015(至少)中,您可以右键单击 XAML 设计器中的控件,然后选择“编辑样式”->“编辑副本”来查看和编辑控件的默认模板。比打开 Blend、下载样式查看器或在网络上搜索要容易得多。
In Visual Studio 2015 (at least) you can right click the control in the XAML designer and select Edit Style->Edit a Copy to view and edit the default template for a control. Much easier than cracking open Blend, downloading a style viewer, or searching the web.
您可以在 微软文档。
此外,有几种工具可以从程序集中读取样式。
例如,您可以使用Style Snooper。
但是,对于您的场景(获取内置模板),上面的文档链接应该是最简单的。
You can find the templates for all themes at Microsoft Docs.
Furthermore, there are several tools out there which can read the styles from an assembly.
For example, you could use Style Snooper.
However, for your scenario (getting the built-in templates), the above documentation link should be the easiest.
我通过谷歌几次到达这个问题,但看不到我想要的链接,所以这里是......
这些链接具有每个框架控件的以下信息:
I arrived at this question via Google a few times, and could not see the link I wanted, so here it is...
These links have the following info for each framework control:
对于 VS 2022 社区:
For VS 2022 Community:
作为 这篇博文说,使用此代码(调用一次)并读取输出文件(defaultTemplate.xml):
在我看来,这是最好的方法。
某些元素(例如
DataGridCell
)无法通过 Visual Studio 调整提取:属性
>模板
>转换为新资源...< /code> 因为您无法显式定义任何 DataGridCell。
As this blog post says, use this code (call it once) and read the output file (defaultTemplate.xml):
In my opinion this is the best method.
Some elements like
DataGridCell
are not extractable through Visual Studio tweak:Properties
>Template
>Convert to New Resource...
because you can't explicitly define any DataGridCell.长话短说,这似乎是现在的链接:
https://learn.microsoft.com/en-us/dotnet/framework/wpf/controls/button-styles-and-templates
(我从该页面复制了按钮的模板,它看来确实是那个。)
Long story short, this seems to be the link nowadays:
https://learn.microsoft.com/en-us/dotnet/framework/wpf/controls/button-styles-and-templates
(I copied the template for button from that page, and it does indeed seem to be the one.)