【发布时间】:2016-12-28 00:20:28
【问题描述】:
以下定义用作GridView、SelectionMode“Single”的ItemContainer 样式。当一个元素被选中时,一个特定的字形变为可见以指示选择。
它适用于 Windows 8.1,但在 UWP 中,它接受更改的状态:Selected 使字形出现,但不会恢复到原始状态(状态 Unselected),即使SelectionChanged 事件将旧的选择作为已删除的项目,字形也会保持选择。
其他状态(如Pressed和Focused)也存在类似问题,为了简单起见,我只是不显示完整的VisualStateManager。
<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"
To="1"
Duration="0" />
</Storyboard>
</VisualState>
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="SelectingGlyph"
Storyboard.TargetProperty="Opacity"
To="1"
Duration="0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
也试过了
<VisualState x:Name="Unselected">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="SelectingGlyph"
Storyboard.TargetProperty="Opacity"
To="0"
Duration="0" />
</Storyboard>
</VisualState>
但没有帮助。
【问题讨论】:
-
您确定您的视觉状态组和视觉状态名称正确吗? msdn.microsoft.com/en-us/library/windows/apps/mt299136.aspx
标签: xaml animation uwp visualstatemanager visualstates