Пример #1
0
        /// <summary>
        /// Coerces the Value value.
        /// </summary>
        private static object CoerceValueValue(DependencyObject d, object value)
        {
            RatingsControl ratingsControl = (RatingsControl)d;
            Decimal        current        = (Decimal)value;

            if (current < ratingsControl.Minimum)
            {
                current = ratingsControl.Minimum;
            }
            if (current > ratingsControl.Maximum)
            {
                current = ratingsControl.Maximum;
            }
            return(current);
        }
Пример #2
0
        /// <summary>
        /// Coerces the NumberOfStars value.
        /// </summary>
        private static object CoerceNumberOfStarsValue(DependencyObject d, object value)
        {
            RatingsControl ratingsControl = (RatingsControl)d;
            Int32          current        = (Int32)value;

            if (current < ratingsControl.Minimum)
            {
                current = ratingsControl.Minimum;
            }
            if (current > ratingsControl.Maximum)
            {
                current = ratingsControl.Maximum;
            }
            return(current);
        }
Пример #3
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);
            }
        }