zoukankan      html  css  js  c++  java
  • 【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);
    
  • 相关阅读:
    QT实现软件重启
    Qt 延时
    gcc 创建库及使用
    verilog 奇数分频设计
    内核中的 likely() 与 unlikely()
    TFT LCD 参数详解
    手动安装m4, autoconf, automake, libtool
    [其他] 蒙特卡洛(Monte Carlo)模拟手把手教基于EXCEL与Crystal Ball的蒙特卡洛成本模拟过程实例:
    Origin9.1如何绘制风向玫瑰图(Binned Data)?
    Origin9.1如何使用原始数据(Raw Data)绘制风向玫瑰图
  • 原文地址:https://www.cnblogs.com/oiliu/p/5584038.html
Copyright © 2011-2022 走看看