• 【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);
    
  • 相关阅读:
    ios 开发日记 15
    ios开发日记
    ios 开发日记 13-剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
    ios开发日记-12 sdwebImage内存泄露
    ios 开发日记 9
    ios开发日记11 对tableView三种计算动态行高方法的分析
    ios开发日记 10- CGPathAddArc和CGPathAddArcToPoint函数
    ios开发日记10
    关于appStore不显示构建版本的问题
    UITextField/UITextView限制字数
  • 原文地址:https://www.cnblogs.com/oiliu/p/5584038.html
Copyright © 2020-2023  润新知