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();
                    }
    
                }
            }
  • 相关阅读:
    Linux内核驱动--硬件访问I/O【原创】
    Linux内核驱动--mmap设备方法【原创】
    Linux系统调用的运行过程【转】
    蓝牙Bluetooth技术手册规范下载【转】
    FarBox--另类有趣的网站服务【转】
    蓝牙HID协议笔记【转】
    linux 串口0x03,0x13的问题【转】
    CC254x/CC2540/CC2541库函数速查(转)
    BLE获取iphone mac地址的方法--【原创】
    用secureCRT操作ubuntu终端
  • 原文地址:https://www.cnblogs.com/easy5weikai/p/3335519.html
Copyright © 2011-2022 走看看