How do I view a XAML control's default templates and styles without the Visual Studio designer?

一曲冷凌霜 提交于 2021-01-28 13:05:34

问题


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):

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.

[...]

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.

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?

Thanks!


回答1:


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

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

    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.

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

  • 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).



来源:https://stackoverflow.com/questions/64932733/how-do-i-view-a-xaml-controls-default-templates-and-styles-without-the-visual-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!