如何获取 UWP 中控件的支持的可视状态

huangapple go评论73阅读模式
英文:

How to get supported visual states of a control in UWP

问题

ControlTemplate中,我已定义了各种视觉状态,以更改控件在特定状态下的外观。对于ListBox,我不知道要使用哪些视觉状态。

有没有一种方法可以获取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>
英文:

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?

&lt;ControlTemplate TargetType=&quot;ListBoxItem&quot;&gt;
    &lt;Border Background=&quot;{TemplateBinding Background}&quot;
            BorderBrush=&quot;{TemplateBinding BorderBrush}&quot;
            BorderThickness=&quot;{TemplateBinding BorderThickness}&quot;&gt;
        &lt;VisualStateManager.VisualStateGroups&gt;
            &lt;VisualStateGroup x:Name=&quot;?&quot;&gt;
                &lt;VisualState x:Name=&quot;?&quot; /&gt;
                &lt;VisualState x:Name=&quot;?&quot; /&gt;
                &lt;VisualState x:Name=&quot;?&quot; /&gt;
                &lt;VisualState x:Name=&quot;?&quot; /&gt;
                &lt;VisualState x:Name=&quot;?&quot; /&gt;
            &lt;/VisualStateGroup&gt;
        &lt;/VisualStateManager.VisualStateGroups&gt;

        &lt;Grid Background=&quot;Transparent&quot;&gt;
            &lt;ContentPresenter x:Name=&quot;ContentPresenter&quot;
                                FontStyle=&quot;Italic&quot;
                                FontWeight=&quot;Bold&quot;
                                Content=&quot;{TemplateBinding Content}&quot;
                                HorizontalAlignment=&quot;{TemplateBinding HorizontalContentAlignment}&quot;
                                VerticalAlignment=&quot;{TemplateBinding VerticalContentAlignment}&quot;
                                Margin=&quot;{TemplateBinding Padding}&quot; /&gt;
        &lt;/Grid&gt;
    &lt;/Border&gt;
&lt;/ControlTemplate&gt;

答案1

得分: 4

在操作系统定义的资源中直接搜索,以查找所有支持的可视状态、样式和模板的最简单方法是在以下位置:

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

在这个文件夹中,你应该会找到包含所有控件样式和模板的generic.xaml。在这些样式中,你可以检查VisualStateManager.VisualStateGroups来找到你需要的一切 :-)。请确保不要对文件本身进行任何更改。

**注意:**在将来(在WinUI 3.0发布后),所有样式都将作为WinUI GitHub仓库的一部分提供。

英文:

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\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 如何获取 UWP 中控件的支持的可视状态 . 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.

huangapple
  • 本文由 发表于 2020年1月6日 23:39:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614913.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定