2

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!

Disclaimer: I work for Microsoft.

1 Answer 1

4

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

3
  • Thank you! Is there a way to do this that does not rely on IntelliSense or Visual Studio? For example, is this file present in the github.com/microsoft/microsoft-ui-xaml repo?
    – citelao
    Nov 30, 2020 at 19:32
  • 1
    The link mentioned by you is related with WinUI library. If you want the generic.xaml file which contains XAML controls’ default templates and styles, you could find it in your local computer. The location of generic.xaml file is C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.18362.0\Generic. 10.0.18362.0 is the version of SDK, you could select the version of SDK that you are using.
    – YanGu
    Dec 1, 2020 at 2:02
  • Thank you! That's what I was hoping for. I added the file location to the answer.
    – citelao
    Dec 1, 2020 at 17:12

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.