/// <summary> /// Updates the needle rotation, the trail, and the value text according to the new value. /// </summary> private static void OnValueChanged(DependencyObject d) { RadialGauge c = (RadialGauge)d; if (!Double.IsNaN(c.Value)) { var middleOfScale = 100 - ScalePadding - c.ScaleWidth / 2; var valueText = c.GetTemplateChild(ValueTextPartName) as TextBlock; c.ValueAngle = c.ValueToAngle(c.Value); // Needle if (c._needle != null) { c._needle.RotationAngleInDegrees = (float)c.ValueAngle; } // Trail var trail = c.GetTemplateChild(TrailPartName) as Path; if (trail != null) { if (c.ValueAngle > MinAngle) { trail.Visibility = Visibility.Visible; var pg = new PathGeometry(); var pf = new PathFigure(); pf.IsClosed = false; pf.StartPoint = c.ScalePoint(MinAngle, middleOfScale); var seg = new ArcSegment(); seg.SweepDirection = SweepDirection.Clockwise; // We start from -150, so +30 becomes a large arc. seg.IsLargeArc = c.ValueAngle > (180 + MinAngle); seg.Size = new Size(middleOfScale, middleOfScale); seg.Point = c.ScalePoint(Math.Min(c.ValueAngle, MaxAngle), middleOfScale); // On overflow, stop trail at MaxAngle. pf.Segments.Add(seg); pg.Figures.Add(pf); trail.Data = pg; } else { trail.Visibility = Visibility.Collapsed; } } // Value Text if (valueText != null) { valueText.Text = c.Value.ToString(c.ValueStringFormat); } } }
private void SquareOfOldPage_Loaded(object sender, RoutedEventArgs e) { var random = new Random((int)DateTime.Now.Ticks); foreach (var square in SquareOfSquares.Squares) { var gauge = new XamlBrewer.Uwp.Controls.RadialGauge() { Height = square.ActualHeight, Width = square.ActualWidth }; gauge.TrailBrush = new SolidColorBrush(square.RandomColor()); gauge.TickBrush = new SolidColorBrush(square.RandomColor()); gauge.ScaleTickBrush = App.Current.Resources["PageBackgroundBrush"] as SolidColorBrush; gauge.NeedleBrush = App.Current.Resources["NeedleBrush"] as SolidColorBrush; gauge.ValueBrush = gauge.TrailBrush; gauge.Maximum = 50; gauge.TickSpacing = 5; gauge.ScaleWidth = random.Next(5, 77); gauge.Maximum = 50; var side = square.Side(); gauge.Value = side; square.Content = gauge; } }