简体   繁体   English

CommonStates不会自动触发

[英]CommonStates not triggered automatically

I am trying to use the CommonStates in order to animate my user control. 我正在尝试使用CommonStates来设置我的用户控件的动画。 I tried the following: 我尝试了以下方法:

 <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>

I can produce the changes by manually calling UpdateStates(true) , but refering to the documentation the commonstates should be triggered automatically. 我可以通过手动调用UpdateStates(true)来产生更改,但是请参考文档,共同状态应自动触发。

Any idea what I do wrong? 知道我做错了什么吗?

Some controls have defined visual states and switch between them in their implementation, for example Button or Checkbox . 一些控件定义了视觉状态,并在其实现中进行切换,例如ButtonCheckbox In such case these states are listed in the documentation like here . 在这种情况下,这些状态在此处的文档中列出。 Unfortunately Grid is not one of them so if you want similar behavior there, you will need to add event handlers and use GoToState manually. 不幸的是Grid并不是其中之一,因此如果您想在其中使用类似的行为,则需要添加事件处理程序并手动使用GoToState You can also create a custom derived class from Grid to have this behavior reusable. 您还可以从Grid创建一个自定义派生类,以使此行为可重复使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM