英文:
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?
<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>
答案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 . 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论