[UWP] [C#] VisualStateManager不会恢复到原始状态 [英] [UWP][C#]VisualStateManager does not revert to original state
问题描述
以下定义用作GridView的ItemContainer样式,SelectionMode ="Single"。当选择一个元素时,一个特定的字形变得可见以表示选择。
它适用于8.1,但是使用UWP它接受改变的状态: Selected 使字形显示,但不会恢复到原始状态:字形保持选择已更改(状态
未选择),即使SelectionChanged事件将旧选择作为已删除项目。
其他州存在类似问题(如按下和聚焦),我只是不显示完整的VisualStateManager以简化。
The following definition is used as ItemContainer style for a GridView, SelectionMode="Single". When an element is selected, a particular glyph becomes visible to indicate selection.
It works right with 8.1, but with UWP it accepts changed state: Selected makes the glyph to appear, but does not revert to the original state: glyph stays with selection changed (state
Unselected), even though SelectionChanged event brings the old selection as removed item.
Similar problems exist for other states (like Pressed and Focused), I just don't show the full VisualStateManager for simplicity.
<Style x:Key="MyItemContainerStyle" TargetType="SelectorItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="SelectorItem">
<Border>
<Grid >
<!-- Layout of the grid -->
</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected" />
<VisualState x:Name="SelectedUnfocused">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="SelectingGlyph"
Storyboard.TargetProperty="Opacity"
Duration="0" To="1" />
</Storyboard>
</VisualState>
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="SelectingGlyph"
Storyboard.TargetProperty="Opacity"
Duration="0" To="1" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
也试过了
Tried also
<VisualState x:Name="Unselected">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="SelectingGlyph"
Storyboard.TargetProperty="Opacity"
Duration="0" To="0" />
</Storyboard>
</VisualState>
$
没有帮助
Didn't help
推荐答案
您好pcyanide,
尝试使用"正常"和"正常"而不是"取消选择"。
Hi pcyanide,
Try using "Normal" instead of "Unselected".
<VisualState x:Name="Normal">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="SelectingGlyph"
Storyboard.TargetProperty="Opacity"
Duration="0" To="0" />
</Storyboard>
</VisualState>
这篇关于[UWP] [C#] VisualStateManager不会恢复到原始状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!