领胜LDS 键盘AOI检测项目
xcd
2020-06-24 d6c577e17ee7bb5331dd51d803f9b42441b0f0e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Windows;
using System.Windows.Media.Animation;
 
namespace Bro.Common.ImageCanvas
{
    /// <summary>
    /// A helper class to simplify animation.
    /// </summary>
    internal static class AnimationHelper
    {
        /// <summary>
        /// Starts an animation to a particular value on the specified dependency property.
        /// </summary>
        public static void StartAnimation(UIElement animatableElement, DependencyProperty dependencyProperty, double toValue, double animationDurationSeconds, bool useAnimations)
        {
            StartAnimation(animatableElement, dependencyProperty, toValue, animationDurationSeconds, null, useAnimations);
        }
 
        /// <summary>
        /// Starts an animation to a particular value on the specified dependency property.
        /// You can pass in an event handler to call when the animation has completed.
        /// </summary>
        public static void StartAnimation(UIElement animatableElement, DependencyProperty dependencyProperty, double toValue, double animationDurationSeconds, EventHandler completedEvent, bool useAnimations)
        {
            if (useAnimations)
            {
                var fromValue = (double)animatableElement.GetValue(dependencyProperty);
 
                var animation = new DoubleAnimation
                {
                    From = fromValue,
                    To = toValue,
                    Duration = TimeSpan.FromSeconds(animationDurationSeconds)
                };
 
                animation.Completed += delegate (object sender, EventArgs e)
                {
                    //
                    // When the animation has completed bake final value of the animation
                    // into the property.
                    //
                    animatableElement.SetValue(dependencyProperty, animatableElement.GetValue(dependencyProperty));
                    CancelAnimation(animatableElement, dependencyProperty);
                    completedEvent?.Invoke(sender, e);
                };
                animation.Freeze();
                animatableElement.BeginAnimation(dependencyProperty, animation);
            }
            else
            {
                animatableElement.SetValue(dependencyProperty, toValue);
                completedEvent?.Invoke(null, new EventArgs());
            }
        }
 
        /// <summary>
        /// Cancel any animations that are running on the specified dependency property.
        /// </summary>
        public static void CancelAnimation(UIElement animatableElement, DependencyProperty dependencyProperty)
        {
            animatableElement.BeginAnimation(dependencyProperty, null);
        }
    }
}