Exemplo n.º 1
0
        /// <summary>
        /// Updates the values of the rating items.
        /// </summary>
        private void UpdateValues()
        {
            IList <RatingItem> ratingItems = GetRatingItems().ToList();

            RatingItem oldSelectedItem = this.GetSelectedRatingItem();

            IEnumerable <Tuple <RatingItem, double> > itemAndWeights =
                EnumerableFunctions
                .Zip(
                    ratingItems,
                    ratingItems
                    .Select(ratingItem => 1.0)
                    .GetWeightedValues(WeightedValue),
                    (item, percent) => Tuple.Create(item, percent));

            foreach (Tuple <RatingItem, double> itemAndWeight in itemAndWeights)
            {
                itemAndWeight.Item1.Value = itemAndWeight.Item2;
            }

            RatingItem newSelectedItem = this.GetSelectedRatingItem();

            if (HoveredRatingItem == null)
            {
                DisplayValue = WeightedValue;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the value and actual value of the rating items.
        /// </summary>
        private void UpdateDisplayValues()
        {
            IList <RatingItem> ratingItems = GetRatingItems().ToList();

            IEnumerable <Tuple <RatingItem, double> > itemAndWeights =
                EnumerableFunctions
                .Zip(
                    ratingItems,
                    ratingItems
                    .Select(ratingItem => 1.0)
                    .GetWeightedValues(WeightedValue),
                    (item, percent) => Tuple.Create(item, percent));

            RatingItem selectedItem = null;
            Tuple <RatingItem, double> selectedItemAndWeight = itemAndWeights.LastOrDefault(i => i.Item2 > 0.0);

            if (selectedItemAndWeight != null)
            {
                selectedItem = selectedItemAndWeight.Item1;
            }
            else
            {
                selectedItem = GetSelectedRatingItem();
            }

            foreach (Tuple <RatingItem, double> itemAndWeight in itemAndWeights)
            {
                if (SelectionMode == RatingSelectionMode.Individual && itemAndWeight.Item1 != selectedItem)
                {
                    itemAndWeight.Item1.DisplayValue = 0.0;
                }
                else
                {
                    itemAndWeight.Item1.DisplayValue = itemAndWeight.Item2;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates the hover states of the rating items.
        /// </summary>
        private void UpdateHoverStates()
        {
            if (HoveredRatingItem != null && IsEnabled)
            {
                IList <RatingItem> ratingItems = GetRatingItems().ToList();
                int indexOfItem = ratingItems.IndexOf(HoveredRatingItem);

                double total  = ratingItems.Count();
                double filled = indexOfItem + 1;

                this.DisplayValue = filled / total;

                for (int cnt = 0; cnt < ratingItems.Count; cnt++)
                {
                    RatingItem ratingItem = ratingItems[cnt];
                    if (cnt <= indexOfItem && this.SelectionMode == RatingSelectionMode.Continuous)
                    {
                        VisualStates.GoToState(ratingItem, true, VisualStates.StatePointerOver);
                    }
                    else
                    {
                        IUpdateVisualState updateVisualState = (IUpdateVisualState)ratingItem;
                        updateVisualState.UpdateVisualState(true);
                    }
                }
            }
            else
            {
                this.DisplayValue = this.Value;

                foreach (IUpdateVisualState updateVisualState in GetRatingItems().OfType <IUpdateVisualState>())
                {
                    updateVisualState.UpdateVisualState(true);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets a rating item at a certain index offset from another 
 /// rating item.
 /// </summary>
 /// <param name="ratingItem">The rating item.</param>
 /// <param name="offset">The rating item at an offset from the 
 /// index of the rating item.</param>
 /// <returns>The rating item at the offset.</returns>
 private RatingItem GetRatingItemAtOffsetFrom(RatingItem ratingItem, int offset)
 {
     IList<RatingItem> ratingItems = GetRatingItems().ToList();
     int index = ratingItems.IndexOf(ratingItem);
     if (index == -1)
     {
         return null;
     }
     index += offset;
     if (index >= 0 && index < ratingItems.Count)
     {
         ratingItem = ratingItems[index];
     }
     else
     {
         ratingItem = null;
     }
     return ratingItem;
 }
Exemplo n.º 5
0
 /// <summary>
 /// This method is invoked when the rating item value is changed.
 /// </summary>
 /// <param name="ratingItem">The rating item that has changed.</param>
 /// <param name="newValue">The new value.</param>
 protected virtual void OnRatingItemValueSelected(RatingItem ratingItem, double newValue)
 {
     List<RatingItem> ratingItems = GetRatingItems().ToList();
     double total = ratingItems.Count();
     this.Value = ratingItems.IndexOf(ratingItem) + 1;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Selects a rating item.
 /// </summary>
 /// <param name="selectedRatingItem">The selected rating item.</param>
 internal void SelectRatingItem(RatingItem selectedRatingItem)
 {
     if (this.IsEnabled)
     {
         IList<RatingItem> ratingItems = GetRatingItems().ToList();
         IEnumerable<double> weights = ratingItems.Select(ratingItem => 1.0);
         double total = ratingItems.Count();
         double percent;
         if (total != 0)
         {
             percent = weights.Take(ratingItems.IndexOf(selectedRatingItem) + 1).Sum() / total;
             this.Value = percent;
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// DisplayValueProperty property changed handler.
        /// </summary>
        /// <param name="d">RatingItem that changed its DisplayValue.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnDisplayValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RatingItem source = (RatingItem)d;

            source.OnDisplayValueChanged((double)e.OldValue, (double)e.NewValue);
        }