开发者

Animation freezes the value it animates over?

开发者 https://www.devze.com 2023-04-04 08:28 出处:网络
I\'m working on creating a \"slide to unlock\" button for shits and giggles in WPF. I have two images to display: the outer black box (SwipeBack) that\'s stationary and the inner white box (SwipeBar)

I'm working on creating a "slide to unlock" button for shits and giggles in WPF. I have two images to display: the outer black box (SwipeBack) that's stationary and the inner white box (SwipeBar) that is the slider. OnTouchDown of the slider image, I set a bool IsDragging to true. OnTouchMove, I move the image by adjusting it's left margin (there might be a better way, but this works). Here is the OnTouchMove code:

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

In my OnTouchUp event, I set IsDragging back to false and run an animation to return the SwipeBar back to the resting left hand position (back at a margin of 15), here's that code:

    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, sl开发者_开发百科ideBack);
    }

The problem I'm having is that after the first time the animation runs, I can no longer manipulate SwipeBar's margin to do another slide. I'm new to WPF and especially WPF animations, but I believe I can't change the margin after the first animation because of the animation. I've tried giving the animation a duration, but even after the time expires (or retry count) the margin still can't be modified.


There is a MSDN article on this behavior, i think it applies to non-storyboard animations as well: How to: Set a Property After Animating It with a Storyboard

(Just the remove-storyboard-option is irrelevant)

0

精彩评论

暂无评论...
验证码 换一张
取 消