protected override void OnKeyDown(KeyRoutedEventArgs e) #endif { base.OnKeyDown(e); if (e.Handled || !IsEnabled) { return; } // Some keys (e.g. Left/Right) need to be translated in RightToLeft mode #if WORKINPROGRESS #if MIGRATION Key invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, e.Key); #else System.VirtualKey invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, e.Key); #endif #else #if MIGRATION Key invariantKey = InteractionHelper.GetLogicalKey(FlowDirection.LeftToRight, e.Key); #else System.VirtualKey invariantKey = InteractionHelper.GetLogicalKey(FlowDirection.LeftToRight, e.Key); #endif #endif bool isExpanded = IsExpanded; switch (ExpandDirection) { case ExpandDirection.Down: #if MIGRATION if ((isExpanded && invariantKey == Key.Up) || (!isExpanded && invariantKey == Key.Down)) #else if ((isExpanded && invariantKey == System.VirtualKey.Up) || (!isExpanded && invariantKey == System.VirtualKey.Down)) #endif { IsExpanded = !isExpanded; } break; case ExpandDirection.Up: #if MIGRATION if ((isExpanded && invariantKey == Key.Down) || (!isExpanded && invariantKey == Key.Up)) #else if ((isExpanded && invariantKey == System.VirtualKey.Down) || (!isExpanded && invariantKey == System.VirtualKey.Up)) #endif { IsExpanded = !isExpanded; } break; case ExpandDirection.Left: #if MIGRATION if ((isExpanded && invariantKey == Key.Right) || (!isExpanded && invariantKey == Key.Left)) #else if ((isExpanded && invariantKey == System.VirtualKey.Right) || (!isExpanded && invariantKey == System.VirtualKey.Left)) #endif { IsExpanded = !isExpanded; } break; case ExpandDirection.Right: #if MIGRATION if ((isExpanded && invariantKey == Key.Left) || (!isExpanded && invariantKey == Key.Right)) #else if ((isExpanded && invariantKey == System.VirtualKey.Left) || (!isExpanded && invariantKey == System.VirtualKey.Right)) #endif { IsExpanded = !isExpanded; } break; } }
protected override void OnKeyDown(KeyRoutedEventArgs 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 VirtualKey invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, e.Key); switch (invariantKey) { case VirtualKey.Left: { RatingItem ratingItem = FocusManager.GetFocusedElement() as RatingItem; if (ratingItem != null) { ratingItem = GetRatingItemAtOffsetFrom(ratingItem, -1); } else { ratingItem = GetRatingItems().FirstOrDefault(); } if (ratingItem != null) { if (ratingItem.Focus(FocusState.Keyboard)) { e.Handled = true; } } } break; case VirtualKey.Right: { RatingItem ratingItem = FocusManager.GetFocusedElement() as RatingItem; if (ratingItem != null) { ratingItem = GetRatingItemAtOffsetFrom(ratingItem, 1); } else { ratingItem = GetRatingItems().FirstOrDefault(); } if (ratingItem != null) { if (ratingItem.Focus(FocusState.Keyboard)) { e.Handled = true; } } } break; case VirtualKey.Add: { if (this.IsEnabled) { RatingItem ratingItem = GetSelectedRatingItem(); if (ratingItem != null) { ratingItem = GetRatingItemAtOffsetFrom(ratingItem, 1); } else { ratingItem = GetRatingItems().FirstOrDefault(); } if (ratingItem != null) { ratingItem.SelectValue(); e.Handled = true; } } } break; case VirtualKey.Subtract: { if (this.IsEnabled) { RatingItem ratingItem = GetSelectedRatingItem(); if (ratingItem != null) { ratingItem = GetRatingItemAtOffsetFrom(ratingItem, -1); } if (ratingItem != null) { ratingItem.SelectValue(); e.Handled = true; } } } break; } }