在哪里可以找到默认的 WPF 控件模板?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3548319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:03:31  来源:igfitidea点击:

Where can i find the default WPF Control templates?

wpfstylescontroltemplategridviewcolumn

提问by Manish Basantani

As per this MSDNlink,

根据此MSDN链接,

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

没有办法只替换控件的可视化树的一部分;要更改控件的可视化树,您必须将控件的 Template 属性设置为其新的和完整的 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.

我正在尝试禁用 GridViewColumnHeader 的单击行为(我需要删除原始控件模板中的一些触发器),但我无法找到本机“ColumnHeaderContainerStyle”。我发现的所有这些似乎都已经进行了一些自定义,并且很难获得原始外观和感觉。

Can someone please suggest me how/where can i get the original control templates as defined in the native WPF controls?

有人可以建议我如何/在哪里可以获得本机 WPF 控件中定义的原始控件模板吗?

Thanks for your interest.

谢谢你的关注。

采纳答案by gehho

You can find the templates for all themes here at MSDN.

您可以在 MSDN 上找到所有主题的模板。

(The link should take you directly to the correct location on the page. After the whole page is loaded (might take some seconds), the "Themes" section should be at the top of your browser's content.)

(该链接应将您直接带到页面上的正确位置。加载整个页面后(可能需要几秒钟),“主题”部分应位于浏览器内容的顶部。)

EDIT:It seems like the link above does not work any longer. Please refer to the link given in the post by McGarnagle.

编辑:上面的链接似乎不再有效。请参阅McGarnagle 帖子中给出的链接。

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 MSDN link should be the easiest.

此外,有几种工具可以从程序集中读取样式。例如,您可以使用Style Snooper。但是,对于您的场景(获取内置模板),上面的 MSDN 链接应该是最简单的。

回答by John Stritenberger

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.

在 Visual Studio 2015(至少)中,您可以右键单击 XAML 设计器中的控件并选择“编辑样式-> 编辑副本”以查看和编辑控件的默认模板。比打开 Blend、下载样式查看器或搜索网络要容易得多。

回答by McGarnagle

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:

这些链接包含每个框架控件的以下信息:

  • Named template parts
  • Visual states
  • Full XAML default control template and resources
  • 命名模板部件
  • 视觉状态
  • 完整的 XAML 默认控件模板和资源

回答by Mike Nakis

Long story short, this seems to be the link nowadays:

长话短说,这似乎是现在的链接:

https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/button-styles-and-templates

https://docs.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.)

(我从那个页面复制了按钮的模板,它似乎确实是那个。)