コード例 #1
0
        /// <summary>
        /// DisplayValueProperty property changed handler.
        /// </summary> 
        /// <param name="oldValue">The old value.</param> 
        /// <param name="newValue">The new value.</param>
        private void OnDisplayValueChanged(double oldValue, double newValue) {
            if (!_settingDisplayValue) {
                _settingDisplayValue = true;

                this.DisplayValue = oldValue;

                throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Properties.Resources.InvalidAttemptToChangeReadOnlyProperty", "DisplayValue"));
            }
            else {
                if (newValue <= 0.0) {
                    VisualStates.GoToState(this, true, StateEmpty);
                }
                else if (newValue >= 1.0) {
                    VisualStates.GoToState(this, true, StateFilled);
                }
                else {
                    VisualStates.GoToState(this, true, StatePartial);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Updates the hover states of the rating items.
        /// </summary>
        private void UpdateHoverStates()
        {
            if (HoveredRatingItem != null && !IsReadOnly)
            {
                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.StateMouseOver);
                    }
                    else
                    {
                        IUpdateVisualState updateVisualState = (IUpdateVisualState)ratingItem;
                        updateVisualState.UpdateVisualState(true);
                    }
                }
            }
            else
            {
                this.DisplayValue = this.Value.GetValueOrDefault();

                foreach (IUpdateVisualState updateVisualState in GetRatingItems().OfType <IUpdateVisualState>())
                {
                    updateVisualState.UpdateVisualState(true);
                }
            }
        }