Bilal
Bilal

Reputation: 114

How to get supported visual states of a control in UWP

In ControlTemplate I've defined various visual states to change the appearance of a control for a certain state. For ListBox I don't know which visual states to use.

Is there a way to get supported visual states of a control in UWP?

<ControlTemplate TargetType="ListBoxItem">
    <Border Background="{TemplateBinding Background}"
            BorderBrush="{TemplateBinding BorderBrush}"
            BorderThickness="{TemplateBinding BorderThickness}">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="?">
                <VisualState x:Name="?" />
                <VisualState x:Name="?" />
                <VisualState x:Name="?" />
                <VisualState x:Name="?" />
                <VisualState x:Name="?" />
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid Background="Transparent">
            <ContentPresenter x:Name="ContentPresenter"
                                FontStyle="Italic"
                                FontWeight="Bold"
                                Content="{TemplateBinding Content}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Margin="{TemplateBinding Padding}" />
        </Grid>
    </Border>
</ControlTemplate>

Upvotes: 1

Views: 608

Answers (1)

Martin Zikmund
Martin Zikmund

Reputation: 39082

The easiest way to find all supported visual states as well as styles and templates is to search directly within the OS-defined resources. On your device go to:

C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\{version}\

In this folder you should find generic.xaml which contains styles and templates for all controls. Within those styles, you can check the VisualStateManager.VisualStateGroups to find out everything you need :-) . Make sure not to make any changes to the file itself.

Note: In the future (after the release of WinUI 3.0) all styles will be available as part of the WinUI GitHub repo.

Upvotes: 4

Related Questions