//表盘重绘 public static void OnPropertyChange(DependencyObject d, DependencyPropertyChangedEventArgs e) { GaugeControl gauge = d as GaugeControl; gauge.UIupdate(); System.Console.WriteLine(); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.GaugeMain = ((MyAgaue2.GaugeControl)(target)); return; case 2: this.LayoutRoot = ((System.Windows.Controls.Grid)(target)); return; case 3: this.test = ((System.Windows.Controls.Grid)(target)); return; case 4: this.OuterEllipse = ((System.Windows.Shapes.Path)(target)); return; case 5: this.InnerEllipse = ((System.Windows.Shapes.Path)(target)); return; case 6: this.Needle = ((System.Windows.Shapes.Path)(target)); return; case 7: this.NeedlePointer = ((System.Windows.Media.PathGeometry)(target)); return; case 8: this.ScaleMarker = ((System.Windows.Controls.Grid)(target)); return; case 9: this.ScaleLabel = ((System.Windows.Controls.TextBlock)(target)); return; case 10: this.ValueLabel = ((System.Windows.Controls.TextBlock)(target)); return; } this._contentLoaded = true; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.userInformation = ((WinDataTest.MainWindow)(target)); return; case 2: this.one = ((MyAgaue2.GaugeControl)(target)); return; case 3: this.two = ((MyAgaue2.GaugeControl)(target)); return; } this._contentLoaded = true; }
/**新增属性封装 * **/ //表盘指针动态变化 public static void OnValueChange(DependencyObject d, DependencyPropertyChangedEventArgs e) { GaugeControl gauge = d as GaugeControl; gauge.angelCurrent = gauge.angleNext; double tempValue = (int)e.NewValue * 1.0 > gauge.MaxValue ? gauge.MaxValue : (int)e.NewValue * 1.0; tempValue = (int)e.NewValue * 1.0 < gauge.MinValue ? gauge.MinValue : (int)e.NewValue * 1.0; double valueInPercent = (tempValue - gauge.MinValue) / (gauge.MaxValue - gauge.MinValue); var valueInDegrees = valueInPercent * (gauge.EndAngle - gauge.StartAngle) + gauge.StartAngle; gauge.angleNext = valueInDegrees; double timeAnimation = Math.Abs(gauge.angelCurrent - gauge.angleNext) * 10; System.Windows.Media.Animation.DoubleAnimation da = new System.Windows.Media.Animation.DoubleAnimation(gauge.angelCurrent, gauge.angleNext, new Duration(TimeSpan.FromMilliseconds(timeAnimation))); da.AccelerationRatio = 1; gauge.rt.BeginAnimation(RotateTransform.AngleProperty, da); }