我正在尝试使用CommonStates
来动画我的用户控件。我尝试了以下方法:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
</VisualState>
<VisualState x:Name="PointerOver">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="circle"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
EnableDependentAnimation="True">
<LinearColorKeyFrame Value="Red"
KeyTime="0:0:0.02" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Ellipse x:Name="circle"
Height="280"
Width="280"
Fill="Green" />
</Grid>
我可以通过手动调用qazxsw poi来生成更改,但是参考文档应该自动触发commonstates。
知道我做错了吗?
一些控件已经定义了视觉状态,并在它们的实现中在它们之间切换,例如UpdateStates(true)
或Button
。在这种情况下,这些状态列在文档Checkbox
中。不幸的是like here不是其中之一,所以如果你想要类似的行为,你需要添加事件处理程序并手动使用Grid
。您还可以从GoToState
创建自定义派生类,以使此行为可重用。