/// <summary> /// Sets up stars when Value or NumberOfStars properties change /// Will only show up to the number of stars requested (up to Maximum) /// so if Value > NumberOfStars * 1, then Value is clipped to maximum /// number of full stars /// </summary> /// <param name="RateControl"></param> private static void SetupStars(RateControl RateControl) { double localValue = RateControl.Value; RateControl.spStars.Children.Clear(); for (int i = 0; i < RateControl.NumberOfStars; i++) { Stars star = new Stars(); star.BackgroundColor = RateControl.BackgroundColor; if (i < localValue) { star.StarForegroundColor = RateControl.StarForegroundColor; } else { star.StarForegroundColor = RateControl.StarFadeColor; } star.StarOutlineColor = RateControl.StarOutlineColor; if (localValue > 1) { star.Value = 1.0; } else if (localValue > 0) { star.Value = localValue; } else { star.Value = 0.0; } localValue -= 1.0; RateControl.spStars.Children.Insert(i, star); } }
/// <summary> /// Handles changes to the NumberOfStars property. /// </summary> private static void OnNumberOfStarsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RateControl RateControl = (RateControl)d; SetupStars(RateControl); }
/// <summary> /// Handles changes to the StarForegroundColor property. /// </summary> private static void OnStarForegroundColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RateControl control = (RateControl)d; foreach (Stars star in control.spStars.Children) { star.StarForegroundColor = (SolidColorBrush)e.NewValue; } }