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 double转换成Qstring
    QT 控件ComboBox
    前端web项目打包(二)
    前端Web打包成可执行程序
    div中下拉框无法点击展开跟选中
    div下多个table并排排列
    VS将数据保存在excel表格中
    关于windows下任务栏应用程序标签消失问题的解决办法
    Java8中map()和flatMap()的区别
    Java对象的深拷贝
  • 原文地址:https://www.cnblogs.com/oiliu/p/5584038.html
Copyright © 2011-2022 走看看