• 【WPF】GridLengthAnimation


    参考 : http://zhidao.baidu.com

    public class GridLengthAnimation : AnimationTimeline
        {
            public static readonly DependencyProperty FromProperty;
            public static readonly DependencyProperty ToProperty;
            public static readonly DependencyProperty EasingFunctionProperty;
    
            static GridLengthAnimation()
            {
                FromProperty = DependencyProperty.Register("From", typeof(GridLength), typeof(GridLengthAnimation));
                ToProperty = DependencyProperty.Register("To", typeof(GridLength), typeof(GridLengthAnimation));
                EasingFunctionProperty = DependencyProperty.Register("EasingFunction", typeof(IEasingFunction), typeof(GridLengthAnimation));
            }
    
            protected override Freezable CreateInstanceCore()
            {
                return new GridLengthAnimation();
            }
    
            public override Type TargetPropertyType
            {
                get { return typeof(GridLength); }
            }
    
            public IEasingFunction EasingFunction
            {
                get
                {
                    return (IEasingFunction)GetValue(GridLengthAnimation.EasingFunctionProperty);
                }
                set
                {
                    SetValue(GridLengthAnimation.EasingFunctionProperty, value);
                }
    
            }
    
            public GridLength From
            {
                get
                {
                    return (GridLength)GetValue(GridLengthAnimation.FromProperty);
                }
                set
                {
                    SetValue(GridLengthAnimation.FromProperty, value);
                }
            }
    
            public GridLength To
            {
                get
                {
                    return (GridLength)GetValue(GridLengthAnimation.ToProperty);
                }
                set
                {
                    SetValue(GridLengthAnimation.ToProperty, value);
                }
            }
    
            public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock)
            {
                double fromValue = ((GridLength)GetValue(GridLengthAnimation.FromProperty)).Value;
                double toValue = ((GridLength)GetValue(GridLengthAnimation.ToProperty)).Value;
    
                IEasingFunction easingFunction = this.EasingFunction;
    
                double progress = (easingFunction != null) ? easingFunction.Ease(animationClock.CurrentProgress.Value) : animationClock.CurrentProgress.Value;
    
                if (fromValue > toValue)
                {
                    return new GridLength((1 - progress) * (fromValue - toValue) + toValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
                }
                else
                {
                    return new GridLength((progress) * (toValue - fromValue) + fromValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
                }
            }
        }
    

     调用

    GridLengthAnimation d = new GridLengthAnimation();
    d.From = new GridLength(0, GridUnitType.Pixel);
    d.To = new GridLength(100, GridUnitType.Pixel);
    d.Duration = TimeSpan.FromSeconds(0.2);
    grid_main.RowDefinitions[0].BeginAnimation(RowDefinition.HeightProperty, d);
    
  • 相关阅读:
    const修饰指针
    C++调用C中编译过的函数要加extern "C"
    linux常用指令(1)
    链式队列实现
    存储类别和类型限定词
    数组,指针和引用
    字符函数和字符串函数
    C/C++编译的程序占用的内存
    结构体1(嵌套使用)
    输入输出函数小结
  • 原文地址:https://www.cnblogs.com/oiliu/p/5584038.html
Copyright © 2020-2023  润新知