/* https://docs.microsoft.com/en-us/fluent-ui/web-components/components/progress-ring */ using Brush = System.Windows.Media.Brush; using Brushes = System.Windows.Media.Brushes; // ReSharper disable once CheckNamespace namespace WPFluent.Controls; /// /// Rotating loading ring. /// public class ProgressRing : System.Windows.Controls.Control { /// /// Identifies the dependency property. /// public static readonly DependencyProperty CoverRingStrokeProperty = DependencyProperty.RegisterAttached( nameof(CoverRingStroke), typeof(Brush), typeof(ProgressRing), new FrameworkPropertyMetadata( Brushes.Black, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender | FrameworkPropertyMetadataOptions.Inherits)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty CoverRingVisibilityProperty = DependencyProperty.Register( nameof(CoverRingVisibility), typeof(Visibility), typeof(ProgressRing), new PropertyMetadata(Visibility.Visible)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty EngAngleProperty = DependencyProperty.Register( nameof(EngAngle), typeof(double), typeof(ProgressRing), new PropertyMetadata(180.0d)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty IndeterminateAngleProperty = DependencyProperty.Register( nameof(IndeterminateAngle), typeof(double), typeof(ProgressRing), new PropertyMetadata(180.0d)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty IsIndeterminateProperty = DependencyProperty.Register( nameof(IsIndeterminate), typeof(bool), typeof(ProgressRing), new PropertyMetadata(false)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty ProgressProperty = DependencyProperty.Register( nameof(Progress), typeof(double), typeof(ProgressRing), new PropertyMetadata(50d, OnProgressChanged)); /// /// Validates the entered and redraws the . /// protected static void OnProgressChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is not ProgressRing control) { return; } control.UpdateProgressAngle(); } /// /// Re-draws depending on . /// protected void UpdateProgressAngle() { var percentage = Progress; if (percentage > 100) { percentage = 100; } if (percentage < 0) { percentage = 0; } // (360 / 100) * percentage var endAngle = 3.6d * percentage; if (endAngle >= 360) { endAngle = 359; } SetCurrentValue(EngAngleProperty, endAngle); } /// /// Gets background ring fill. /// public Brush CoverRingStroke { get => (Brush)GetValue(CoverRingStrokeProperty); internal set => SetValue(CoverRingStrokeProperty, value); } /// /// Gets background ring visibility. /// public Visibility CoverRingVisibility { get => (Visibility)GetValue(CoverRingVisibilityProperty); internal set => SetValue(CoverRingVisibilityProperty, value); } /// /// Gets or sets the . /// public double EngAngle { get => (double)GetValue(EngAngleProperty); set => SetValue(EngAngleProperty, value); } /// /// Gets the when is . /// public double IndeterminateAngle { get => (double)GetValue(IndeterminateAngleProperty); internal set => SetValue(IndeterminateAngleProperty, value); } /// /// Gets or sets a value indicating whether shows actual values () /// or generic, continuous progress feedback. /// public bool IsIndeterminate { get => (bool)GetValue(IsIndeterminateProperty); set => SetValue(IsIndeterminateProperty, value); } /// /// Gets or sets the progress. /// public double Progress { get => (double)GetValue(ProgressProperty); set => SetValue(ProgressProperty, value); } }