Exemplo n.º 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="ratingControl"></param>
        private static void SetupStars(RatingControl ratingControl)
        {
            Decimal localValue = ratingControl.Value;

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

                localValue -= 1.0m;
                ratingControl.spStars.Children.Insert(i, star);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles changes to the NumberOfStars property.
        /// </summary>
        private static void OnNumberOfStarsChanged(DependencyObject d,
                                                   DependencyPropertyChangedEventArgs e)
        {
            d.CoerceValue(MinimumProperty);
            d.CoerceValue(MaximumProperty);
            RatingControl ratingControl = (RatingControl)d;

            SetupStars(ratingControl);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles changes to the StarMaskColor property.
        /// </summary>
        private static void OnStarMaskColorChanged(DependencyObject d,
                                                   DependencyPropertyChangedEventArgs e)
        {
            RatingControl control = (RatingControl)d;

            foreach (StarControl star in control.spStars.Children)
            {
                star.StarMaskColor = (SolidColorBrush)e.NewValue;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Coerces the NumberOfStars value.
        /// </summary>
        private static object CoerceNumberOfStarsValue(DependencyObject d, object value)
        {
            RatingControl ratingControl = (RatingControl)d;
            Int32         current       = (Int32)value;

            if (current < ratingControl.Minimum)
            {
                current = ratingControl.Minimum;
            }
            if (current > ratingControl.Maximum)
            {
                current = ratingControl.Maximum;
            }
            return(current);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Coerces the Value value.
        /// </summary>
        private static object CoerceValueValue(DependencyObject d, object value)
        {
            RatingControl ratingControl = (RatingControl)d;
            Decimal       current       = (Decimal)value;

            if (current < ratingControl.Minimum)
            {
                current = ratingControl.Minimum;
            }
            if (current > ratingControl.Maximum)
            {
                current = ratingControl.Maximum;
            }
            return(current);
        }
Exemplo n.º 6
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="ratingControl"></param>
        private static void SetupStars(RatingControl ratingControl)
        {
            Decimal localValue = ratingControl.Value;

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

                localValue -= 1.0m;
                ratingControl.spStars.Children.Insert(i, star);
            }
        }