diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs b/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs index 7e8f1fa8c..f2068d713 100644 --- a/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs +++ b/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs @@ -61,6 +61,7 @@ namespace Tango.CircularGauge private Double arcradius1; private Double arcradius2; private int animatingSpeedFactor = 6; + private List<FrameworkElement> _toClear; #endregion @@ -77,13 +78,18 @@ namespace Tango.CircularGauge /// Dependency property to Get/Set the Minimum Value /// </summary> public static readonly DependencyProperty MinValueProperty = - DependencyProperty.Register("MinValue", typeof(double), typeof(CircularGaugeControl), null); + DependencyProperty.Register("MinValue", typeof(double), typeof(CircularGaugeControl), new PropertyMetadata(0.0, (d, e) => (d as CircularGaugeControl).OnMinMaxChanged())); /// <summary> /// Dependency property to Get/Set the Maximum Value /// </summary> public static readonly DependencyProperty MaxValueProperty = - DependencyProperty.Register("MaxValue", typeof(double), typeof(CircularGaugeControl), null); + DependencyProperty.Register("MaxValue", typeof(double), typeof(CircularGaugeControl), new PropertyMetadata(100.0, (d, e) => (d as CircularGaugeControl).OnMinMaxChanged())); + + private void OnMinMaxChanged() + { + DrawScale(); + } /// <summary> /// Dependency property to Get/Set the Radius of the gauge @@ -895,6 +901,7 @@ namespace Tango.CircularGauge public CircularGaugeControl() { + _toClear = new List<FrameworkElement>(); _rangeIndicators = new List<Path>(); } @@ -1128,15 +1135,19 @@ namespace Tango.CircularGauge //Reset Pointer MovePointer(ScaleStartAngle); } - - - } //Drawing the scale with the Scale Radius private void DrawScale() { + foreach (var item in _toClear) + { + rootGrid.Children.Remove(item); + } + + _toClear.Clear(); + //Calculate one major tick angle Double majorTickUnitAngle = ScaleSweepAngle / MajorDivisionsCount; @@ -1211,8 +1222,9 @@ namespace Tango.CircularGauge majortickgp.Children.Add(majorticktt); majortickrect.RenderTransform = majortickgp; tb.RenderTransform = majorscalevaluett; - rootGrid.Children.Add(majortickrect); - rootGrid.Children.Add(tb); + + AddToRootGrid(majortickrect); + AddToRootGrid(tb); //Drawing the minor axis ticks @@ -1247,7 +1259,7 @@ namespace Tango.CircularGauge minortickgp.Children.Add(minorticktt); mr.RenderTransform = minortickgp; - rootGrid.Children.Add(mr); + AddToRootGrid(mr); } @@ -1425,11 +1437,20 @@ namespace Tango.CircularGauge rangeIndicator.SetValue(Canvas.ZIndexProperty, 150); // Adding the segment to the root grid - rootGrid.Children.Add(rangeIndicator); + if (!rootGrid.Children.Contains(rangeIndicator)) + { + rootGrid.Children.Add(rangeIndicator); + } return rangeIndicator; } #endregion + + private void AddToRootGrid(FrameworkElement element) + { + rootGrid.Children.Add(element); + _toClear.Add(element); + } } } |
