Animations in visual state do not animate (WinRT)

痴心易碎 提交于 2019-12-24 12:51:08

问题


I am developing on Windows 8.1 RTM. I have a custom control with a custom dependency property of type double. This control has been placed in a user control. I am calling VisualStateManager.GoToState(control, true) on the user control. The animation should transition for 2 seconds. However, it simply snaps from 0 to 1 and from 1 to 0. The callback function is only called with either 0 or 1. If I directly set the dependency property to any value between 0 and 1, it works as expected.

I have the following XAML:

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:controls="using:MyControls" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="TestStates">
            <VisualStateGroup.Transitions>
              <VisualTransition GeneratedDuration="0:0:2"/>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="A">
                <Storyboard>
                    <DoubleAnimation
                        EnableDependentAnimation="True"
                        Duration="0"
                        Storyboard.TargetName="MyControl1"
                        Storyboard.TargetProperty="MyDependencyProperty"
                        To="0"/>
                </Storyboard>
            </VisualState>
            <VisualState x:Name="B">
                <Storyboard>
                    <DoubleAnimation
                        EnableDependentAnimation="True"
                        Duration="0"
                        Storyboard.TargetName="MyControl1"
                        Storyboard.TargetProperty="MyDependencyProperty"
                        To="1"/>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <controls:MyControl x:Name="MyControl1" MyDependencyProperty="0">
</Grid>
</UserControl>

If I set the target property to Opacity, it works.

Looking at previous questions, EnableDependentAnimation seems to be the common culprit for this behavior, but I've already set it to true.

Timeline.AllowDependentAnimations is true.

I've stripped the control down to just the one dependency property with no logic in the callback. Same issue.


回答1:


See i was going through the animation on dependency property and found an intereting point I thought I should share

To be animated, the animation's target property must be a dependency property. Also, to be animated, the target property's value type must be supported by one of the existing Timeline-derived animation types. When an animation is applied and running, the animated value operates at a higher precedence than any value (such as a local value) that the property otherwise has. Animations also have an optional HoldEnd behavior that can cause animations to apply to property values even if the animation visually appears to be stopped.

I dont know may be This will help Here's the link to the documentation

animation



来源:https://stackoverflow.com/questions/18991200/animations-in-visual-state-do-not-animate-winrt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!