动画会冻结它动画的价值吗?

时间:2011-09-09 17:53:26

标签: .net wpf animation

我正在为WPF中的shits和giggles创建一个“slide to unlock”按钮。我有两个要显示的图像:静止的外部黑盒子(SwipeBack)和作为滑块的内部白盒子(SwipeBar)。滑块图像的OnTouchDown,我将bool IsDragging设置为true。 OnTouchMove,我通过调整左边距来移动图像(可能有更好的方法,但这有效)。这是OnTouchMove代码:

    private void SwipeBar_TouchMove(object sender, TouchEventArgs e) {
        if (IsDragging) {
            int x = (int)e.GetTouchPoint(SwipeBack).Position.X;
            int left = (int)(x - SwipeBar.ActualWidth / 2);
            left = Math.Max(15, left);
            left = Math.Min(left, (int)(SwipeBack.ActualWidth - 15 - SwipeBar.ActualWidth));
            Thickness m = SwipeBar.Margin;
            m.Left = left;
            SwipeBar.Margin = m;
        }
    }

在我的OnTouchUp事件中,我将IsDragging设置为false并运行动画以将SwipeBar返回到静止的左手位置(返回15的边距),这是代码:

    private void SwipeBar_TouchUp(object sender, TouchEventArgs e) {
        IsDragging = false;
        ThicknessAnimation slideBack = new ThicknessAnimation();
        slideBack.From = SwipeBar.Margin;
        Thickness to = SwipeBar.Margin;
        to.Left = 15;
        slideBack.To = to;
        ExponentialEase ease = new ExponentialEase();
        ease.Exponent = 7;
        slideBack.EasingFunction = ease;
        SwipeBar.BeginAnimation(Image.MarginProperty, slideBack);
    }

我遇到的问题是,在动画第一次运行后,我再也无法操纵SwipeBar的边距来做另一张幻灯片了。我是WPF的新手,特别是WPF动画,但我相信由于动画,我无法在第一个动画后更改边距。我已尝试给动画一个持续时间,但即使在时间到期后(或重试计数),仍然无法修改边距。

1 个答案:

答案 0 :(得分:0)

有关于此行为的MSDN文章,我认为它也适用于非故事板动画:How to: Set a Property After Animating It with a Storyboard

(只是remove-storyboard-option无关紧要)