博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF 位置转化和动画
阅读量:4677 次
发布时间:2019-06-09

本文共 2814 字,大约阅读时间需要 9 分钟。

位置转化

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();                }            }        }

 

转载于:https://www.cnblogs.com/easy5weikai/p/3335519.html

你可能感兴趣的文章
八LWIP学习笔记之用户编程接口(NETCONN)
查看>>
Git Day02,工作区,暂存区,回退,删除文件
查看>>
Windows Phone 7 Coding4Fun控件简介
查看>>
Nginx 常用命令总结
查看>>
hall wrong behavior
查看>>
Markdown test
查看>>
Collection集合
查看>>
int最大值+1为什么是-2147483648最小值-1为什么是2147483647
查看>>
【C++】const在不同位置修饰指针变量
查看>>
github新项目挂历模式
查看>>
编写jquery插件
查看>>
敏捷开发笔记
查看>>
神秘海域:顶级工作室“顽皮狗”成长史(下)
查看>>
C++指针、引用知多少?
查看>>
services 系统服务的启动、停止、卸载
查看>>
css实现背景图片模糊
查看>>
多线程如何确定线程数
查看>>
UGUI RectTransform
查看>>
学前班
查看>>
手把手教您扩展虚拟内存
查看>>