/// <summary>
 /// Initializes a new instance of the RatingItem class.
 /// </summary>
 public RatingItem()
 {
     #if SILVERLIGHT
     this.DefaultStyleKey = typeof(RatingItem);
     #endif
     _interactionHelper = new InteractionHelper(this);
 }
        /// <summary>
        /// Initializes a new instance of the RatingItem class.
        /// </summary>
        public RatingItem() {
#if SILVERLIGHT
            this.DefaultStyleKey = typeof(RatingItem);
#endif
            _interactionHelper = new InteractionHelper(this);
        }
Ejemplo n.º 3
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (!Interaction.AllowKeyDown(e))
            {
                return;
            }

            base.OnKeyDown(e);

            if (e.Handled)
            {
                return;
            }

            // Some keys (e.g. Left/Right) need to be translated in RightToLeft mode
            Key invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, e.Key);

            switch (invariantKey)
            {
            case Key.Left: {
#if SILVERLIGHT
                RatingItem ratingItem = FocusManager.GetFocusedElement() as RatingItem;
#else
                RatingItem 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
                RatingItem 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 (!this.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 (!this.IsReadOnly)
                {
                    RatingItem ratingItem = GetSelectedRatingItem();
                    if (ratingItem != null)
                    {
                        ratingItem = GetRatingItemAtOffsetFrom(ratingItem, -1);
                    }
                    if (ratingItem != null)
                    {
                        ratingItem.SelectValue();
                        e.Handled = true;
                    }
                }
            }
            break;
            }
        }