问题
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:
- Create a control that uses a built-in style, like
Style="{StaticResource ButtonRevealStyle}"
- Hover the pointer over the
ButtonRevealStyle
and press F12 or right-click and select the Go to Definition option to access the generic.xaml. - 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 ofButton
controls.
Note, please remove the statement
Style="{StaticResource ButtonRevealStyle}"
if you do not need the styleButtonRevealStyle
.- Create a control that uses a built-in style, like
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