Esempio n. 1
0
        /// <summary>
        /// RatingProperty property changed handler.
        /// </summary>
        /// <param name="d">MetroRating that changed its Rating.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnRatingPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MetroRating source = d as MetroRating;
            double      value  = (double)e.NewValue;

            UpdateRatingImage(source, value);
        }
Esempio n. 2
0
        private static void UpdateRatingImage(MetroRating source, double value)
        {
            // make sure the static cache of images is initialized
            InitializeStars();

            // constrain rating between min and max rating values (0-5)
            value = Round(value, 1);
            value = Math.Min(value, MaxRating);
            value = Math.Max(value, MinRating);

            // swap out the image
            if (source._image != null)
            {
                int starIndex = (int)(value * 2);
                source._image.Source = _stars[starIndex];
            }
        }