示例#1
0
        /// <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="ratingsControl"></param>
        private static void SetupStars(RatingsControl ratingsControl)
        {
            Decimal localValue = ratingsControl.Value;

            ratingsControl.spStars.Children.Clear();
            for (int i = 0; i < ratingsControl.NumberOfStars; i++)
            {
                StarControl star = new StarControl();
                star.BackgroundColor     = ratingsControl.BackgroundColor;
                star.StarForegroundColor = ratingsControl.StarForegroundColor;
                star.StarOutlineColor    = ratingsControl.StarOutlineColor;
                if (localValue > 1)
                {
                    star.Value = 1.0m;
                }
                else if (localValue > 0)
                {
                    star.Value = localValue;
                }
                else
                {
                    star.Value = 0.0m;
                }

                localValue -= 1.0m;
                ratingsControl.spStars.Children.Insert(i, star);
            }
        }
示例#2
0
        /// <summary>
        /// Handles changes to the StarForegroundColor property.
        /// </summary>
        private static void OnStarForegroundColorChanged(DependencyObject d,
                                                         DependencyPropertyChangedEventArgs e)
        {
            StarControl control = (StarControl)d;

            control.starForeground.Fill = (SolidColorBrush)e.NewValue;
        }
示例#3
0
        /// <summary>
        /// Handles changes to the StarOutlineColor property.
        /// </summary>
        private static void OnStarOutlineColorChanged(DependencyObject d,
                                                      DependencyPropertyChangedEventArgs e)
        {
            StarControl control = (StarControl)d;

            control.starOutline.Stroke = (SolidColorBrush)e.NewValue;
        }
示例#4
0
        /// <summary>
        /// Handles changes to the BackgroundColor property.
        /// </summary>
        private static void OnBackgroundColorChanged(DependencyObject d,
                                                     DependencyPropertyChangedEventArgs e)
        {
            StarControl control = (StarControl)d;

            control.gdStar.Background = (SolidColorBrush)e.NewValue;
            control.mask.Fill         = (SolidColorBrush)e.NewValue;
        }
示例#5
0
        /// <summary>
        /// Coerces the Value value.
        /// </summary>
        private static object CoerceValueValue(DependencyObject d, object value)
        {
            StarControl starControl = (StarControl)d;
            Decimal     current     = (Decimal)value;

            if (current < starControl.Minimum)
            {
                current = starControl.Minimum;
            }
            if (current > starControl.Maximum)
            {
                current = starControl.Maximum;
            }
            return(current);
        }
示例#6
0
        /// <summary>
        /// Handles changes to the Value property.
        /// </summary>
        private static void OnValueChanged(DependencyObject d,
                                           DependencyPropertyChangedEventArgs e)
        {
            d.CoerceValue(MinimumProperty);
            d.CoerceValue(MaximumProperty);
            StarControl starControl = (StarControl)d;

            if (starControl.Value == 0.0m)
            {
                starControl.starForeground.Fill = Brushes.Gray;
            }
            else
            {
                starControl.starForeground.Fill = starControl.StarForegroundColor;
            }

            Int32 marginLeftOffset = (Int32)(starControl.Value * (Decimal)STAR_SIZE);

            starControl.mask.Margin = new Thickness(marginLeftOffset, 0, 0, 0);
            starControl.InvalidateArrange();
            starControl.InvalidateMeasure();
            starControl.InvalidateVisual();
        }