如何在没有 Visual Studio 设计器的情况下查看 XAML 控件的默认模板和样式? [英] How do I view a XAML control's default templates and styles without the Visual Studio designer?

查看:36
本文介绍了如何在没有 Visual Studio 设计器的情况下查看 XAML 控件的默认模板和样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 MSDN 上的控件模板文档,官方支持的查看控件默认模板和样式的方法是使用 Visual Studio 的设计器(好吧,技术上是文档大纲>,但这仅适用于打开设计器的情况):

According to the Control template documentation on MSDN, the officially-supported way to view a Control's default templates and styles is with Visual Studio's Designer (well, technically the Document Outline, but that only works with the Designer turned on):

将主题应用于控件的一种快速方法是右键单击 Microsoft Visual Studio 文档大纲 上的控件,然后选择编辑主题编辑样式(取决于您右键单击的控件).然后,您可以通过选择应用资源来应用现有主题,或者通过选择创建空白来定义一个新主题.

A fast way to apply themes to your controls is to right-click on a control on the Microsoft Visual Studio Document Outline and select Edit Theme or Edit Style (depending on the control you are right-clicking on). You can then apply an existing theme by selecting Apply Resource or define a new one by selecting Create Empty.

[...]

记录 XAML 控件样式和模板的主题向您展示了使用编辑主题编辑样式技术时看到的相同起始 XAML 的摘录之前解释过.每个主题都列出了视觉状态的名称、使用的主题资源以及包含模板的样式的完整 XAML.如果您已经开始修改模板并希望查看原始模板的外观,或者想验证您的新模板是否具有所有必需的命名视觉状态,这些主题可能是有用的指导.

The topics that document the styles and templates for XAML controls show you excerpts of the same starting XAML you'd see if you used the Edit Theme or Edit Style techniques explained previously. Each topic lists the names of the visual states, the theme resources used, and the full XAML for the style that contains the template. The topics can be useful guidance if you've already started modifying a template and want to see what the original template looked like, or to verify that your new template has all of the required named visual states.

但是,开发人员可能无法访问 Visual Studio 设计器.

However, developers may not have access to the Visual Studio Designer.

我必须使用哪些官方保证最新的替代方法来查看默认模板和样式?

What official, guaranteed-up-to-date alternatives do I have to view the default templates and styles?

谢谢!

推荐答案

您可以在 generic.xaml 文件中找到控件的默认样式.

You can find the default styles of controls in generic.xaml file.

  • 如果自动完成/智能感知在您的 Visual Studio 中运行:

  • If autocomplete/IntelliSense is working in your Visual Studio:

  1. 创建一个使用内置样式的控件,例如 Style="{StaticResource ButtonRevealStyle}"
  2. 将指针悬停在 ButtonRevealStyle 上并按 F12 或右键单击并选择转到定义选项以访问 generic.xaml.
  3. generic.xaml中,您可以在搜索框中使用诸如Windows.UI.Xaml.Controls.Button的默认样式这样的语句来搜索默认样式找到 Button 控件的默认样式.
  1. Create a control that uses a built-in style, like Style="{StaticResource ButtonRevealStyle}"
  2. Hover the pointer over the ButtonRevealStyle and press F12 or right-click and select the Go to Definition option to access the generic.xaml.
  3. In generic.xaml, you can search for a default style with a statement such as Default style for Windows.UI.Xaml.Controls.Button in the search box to find the default style of Button controls.

注意,如果您不需要样式ButtonRevealStyle,请删除声明Style={StaticResource ButtonRevealStyle}".

Note, please remove the statement Style="{StaticResource ButtonRevealStyle}" if you do not need the style ButtonRevealStyle.

您还可以在 Windows SDK 中找到该文件.它位于 C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.18362.0\Generic(其中 10.0.18362.0 是SDK 的版本,您可以将其替换为您正在使用的版本).

You can also find the file as part of the Windows SDK. It lives at C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.18362.0\Generic (where 10.0.18362.0 is the version of the SDK, which you can replace with the version you are using).

这篇关于如何在没有 Visual Studio 设计器的情况下查看 XAML 控件的默认模板和样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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