Пример #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++)
            {
                StarsControl star = new StarsControl();
                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 StarOutlineColor property.
        /// </summary>
        private static void OnStarOutlineColorChanged(DependencyObject d,
                                                      DependencyPropertyChangedEventArgs e)
        {
            StarsControl control = (StarsControl)d;

            control.starOutline.Stroke = (SolidColorBrush)e.NewValue;
        }
Пример #3
0
        /// <summary>
        /// Handles changes to the StarForegroundColor property.
        /// </summary>
        private static void OnStarForegroundColorChanged(DependencyObject d,
                                                         DependencyPropertyChangedEventArgs e)
        {
            StarsControl control = (StarsControl)d;

            control.starForeground.Fill = (SolidColorBrush)e.NewValue;
        }
Пример #4
0
        /// <summary>
        /// Handles changes to the BackgroundColor property.
        /// </summary>
        private static void OnBackgroundColorChanged(DependencyObject d,
                                                     DependencyPropertyChangedEventArgs e)
        {
            StarsControl control = (StarsControl)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)
        {
            StarsControl StarsControl = (StarsControl)d;
            Decimal      current      = (Decimal)value;

            if (current < StarsControl.Minimum)
            {
                current = StarsControl.Minimum;
            }
            if (current > StarsControl.Maximum)
            {
                current = StarsControl.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);
            StarsControl StarsControl = (StarsControl)d;

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

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

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