zoukankan      html  css  js  c++  java
  • WPF 位置转化和动画

    位置转化

            private void DrawScale()
            {
                double majorTickUnitValue = this.ScaleSweepLenth / this.MajorDivisionsCount;
                double minorTickUnitValue = this.ScaleSweepLenth / this.MinorDivisionsCount;
                double correctionOffset = this.rootGrid.Width / 2 ;
    
                Double minvalue = MinValue; ;
    
                //画主刻度
                for (int i = 0; i < this.MajorDivisionsCount; i++)
                {
                    Rectangle majorTickRect = new Rectangle();
                    majorTickRect.Height = this.MajorTickSize.Height;
                    majorTickRect.Width = this.MajorTickSize.Width;
                    majorTickRect.Fill = new SolidColorBrush(this.MajorTickColor);
    
                    TransformGroup majorTickTransformGroup = new TransformGroup();
                    TranslateTransform majorTickTranslateTransform = new TranslateTransform();
    
                    majorTickTranslateTransform.X = i * majorTickUnitValue - correctionOffset;
                    majorTickTranslateTransform.Y = this.MajorMinorDivisionOffset;
    
                    majorTickTransformGroup.Children.Add(majorTickTranslateTransform);
                    majorTickRect.RenderTransform = majorTickTransformGroup;
    
                    this.rootGrid.Children.Add(majorTickRect);
                }
    
            }

    动画

            private void MovePointerUsingAnimate(double oldValue, double newValue)
            {
                if (null != this.pointer)
                {
                    double distanceOldAndNew = Math.Abs(newValue - oldValue);
                    DoubleAnimation doubleAnimation = new DoubleAnimation();
                    double animDuration = 0.0f;
                    Storyboard movingPointerStoryboard = new Storyboard();
                    TransformGroup transformGroup = new TransformGroup();
                    TranslateTransform transform = new TranslateTransform();
               
                    doubleAnimation.From = oldValue;
                    doubleAnimation.To = newValue;
                    animDuration = distanceOldAndNew * animatingSpeedFactor;
                    doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(animDuration));
    
                    movingPointerStoryboard.Completed +=new EventHandler(MovingPointerStoryboardStoryboard_Completed);
                    movingPointerStoryboard.Children.Add(doubleAnimation);
                    Storyboard.SetTarget(doubleAnimation, this.pointer);
    
                    transformGroup.Children.Add(transform);
                    this.pointer.RenderTransform = transformGroup;
    
                    Storyboard.SetTargetProperty(doubleAnimation,
                        new PropertyPath("(Path.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)"));
    
                    if (Math.Abs(oldValue - newValue) > 0)
                    {
                        movingPointerStoryboard.Begin();
                    }
    
                }
            }
  • 相关阅读:
    Leetcode Array 4 Median of Two Sorted Arrays
    vscode Python Pylint(代码检测插件)
    Leetcode Array 1 twoSum
    mysql 配置 安装和 root password 更改
    vscode 编译调试c/c++的环境配置
    chm文件打不开的解决办法
    A + B Problem II
    欢天喜地七仙女——代码规范与计划
    欢天喜地七仙女——项目系统设计与数据库设计
    欢天喜地七仙女——团队Gitee实战训练
  • 原文地址:https://www.cnblogs.com/easy5weikai/p/3335519.html
Copyright © 2011-2022 走看看