/// <summary>
        ///     Adds the RatingItem to the collection of selected items.
        /// </summary>
        /// <remarks>
        ///     This API supports the .NET Framework infrastructure and is not
        ///     intended to be used directly from your code.
        /// </remarks>
        void ISelectionItemProvider.AddToSelection()
        {
            RatingItem owner  = OwnerRatingItem;
            Rating     parent = owner.ParentRating;

            if (parent == null || parent.Value != null)
            {
                throw new InvalidOperationException("Operation cannot be performed.");
            }

            owner.SelectValue();
        }
Exemplo n.º 2
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (!Interaction.AllowKeyDown(e))
            {
                return;
            }

            base.OnKeyDown(e);

            if (e.Handled)
            {
                return;
            }

            switch (e.Key)
            {
            case Key.Left:
            {
#if SILVERLIGHT
                RatingItem ratingItem = FocusManager.GetFocusedElement() as RatingItem;
#else
                var ratingItem = FocusManager.GetFocusedElement(Application.Current.MainWindow) as RatingItem;
#endif
                if (ratingItem != null)
                {
                    ratingItem = GetRatingItemAtOffsetFrom(ratingItem, -1);
                }
                else
                {
                    ratingItem = GetRatingItems().FirstOrDefault();
                }
                if (ratingItem != null)
                {
                    if (ratingItem.Focus())
                    {
                        e.Handled = true;
                    }
                }
            }
            break;

            case Key.Right:
            {
#if SILVERLIGHT
                RatingItem ratingItem = FocusManager.GetFocusedElement() as RatingItem;
#else
                var ratingItem = FocusManager.GetFocusedElement(Application.Current.MainWindow) as RatingItem;
#endif
                if (ratingItem != null)
                {
                    ratingItem = GetRatingItemAtOffsetFrom(ratingItem, 1);
                }
                else
                {
                    ratingItem = GetRatingItems().FirstOrDefault();
                }
                if (ratingItem != null)
                {
                    if (ratingItem.Focus())
                    {
                        e.Handled = true;
                    }
                }
            }
            break;

            case Key.Add:
            {
                if (!IsReadOnly)
                {
                    RatingItem ratingItem = GetSelectedRatingItem();
                    if (ratingItem != null)
                    {
                        ratingItem = GetRatingItemAtOffsetFrom(ratingItem, 1);
                    }
                    else
                    {
                        ratingItem = GetRatingItems().FirstOrDefault();
                    }
                    if (ratingItem != null)
                    {
                        ratingItem.SelectValue();
                        e.Handled = true;
                    }
                }
            }
            break;

            case Key.Subtract:
            {
                if (!IsReadOnly)
                {
                    RatingItem ratingItem = GetSelectedRatingItem();
                    if (ratingItem != null)
                    {
                        ratingItem = GetRatingItemAtOffsetFrom(ratingItem, -1);
                    }
                    if (ratingItem != null)
                    {
                        ratingItem.SelectValue();
                        e.Handled = true;
                    }
                }
            }
            break;
            }
        }