@@ -393,11 +393,8 @@ private void Keyboard_KeyUp(object sender, KeyRoutedEventArgs e)
393
393
case Windows . System . VirtualKey . GamepadLeftThumbstickDown :
394
394
if ( Orientation == Orientation . Vertical )
395
395
{
396
- if ( SelectedIndex < Items . Count - 1 )
397
- {
398
- SelectedIndex ++ ;
399
- }
400
- else if ( e . OriginalKey != Windows . System . VirtualKey . Down )
396
+ bool changed = BoundIncrement ( ) ;
397
+ if ( ! changed && e . OriginalKey != Windows . System . VirtualKey . Down )
401
398
{
402
399
FocusManager . TryMoveFocus ( FocusNavigationDirection . Down ) ;
403
400
}
@@ -411,11 +408,8 @@ private void Keyboard_KeyUp(object sender, KeyRoutedEventArgs e)
411
408
case Windows . System . VirtualKey . GamepadLeftThumbstickUp :
412
409
if ( Orientation == Orientation . Vertical )
413
410
{
414
- if ( SelectedIndex > 0 )
415
- {
416
- SelectedIndex -- ;
417
- }
418
- else if ( e . OriginalKey != Windows . System . VirtualKey . Up )
411
+ bool changed = BoundDecrement ( ) ;
412
+ if ( ! changed && e . OriginalKey != Windows . System . VirtualKey . Up )
419
413
{
420
414
FocusManager . TryMoveFocus ( FocusNavigationDirection . Up ) ;
421
415
}
@@ -429,11 +423,8 @@ private void Keyboard_KeyUp(object sender, KeyRoutedEventArgs e)
429
423
case Windows . System . VirtualKey . GamepadLeftThumbstickLeft :
430
424
if ( Orientation == Orientation . Horizontal )
431
425
{
432
- if ( SelectedIndex > 0 )
433
- {
434
- SelectedIndex -- ;
435
- }
436
- else if ( e . OriginalKey != Windows . System . VirtualKey . Left )
426
+ bool changed = FlowDirection == FlowDirection . LeftToRight ? BoundDecrement ( ) : BoundIncrement ( ) ;
427
+ if ( ! changed && e . OriginalKey != Windows . System . VirtualKey . Left )
437
428
{
438
429
FocusManager . TryMoveFocus ( FocusNavigationDirection . Left ) ;
439
430
}
@@ -447,11 +438,8 @@ private void Keyboard_KeyUp(object sender, KeyRoutedEventArgs e)
447
438
case Windows . System . VirtualKey . GamepadLeftThumbstickRight :
448
439
if ( Orientation == Orientation . Horizontal )
449
440
{
450
- if ( SelectedIndex < Items . Count - 1 )
451
- {
452
- SelectedIndex ++ ;
453
- }
454
- else if ( e . OriginalKey != Windows . System . VirtualKey . Right )
441
+ bool changed = FlowDirection == FlowDirection . LeftToRight ? BoundIncrement ( ) : BoundDecrement ( ) ;
442
+ if ( ! changed && e . OriginalKey != Windows . System . VirtualKey . Right )
455
443
{
456
444
FocusManager . TryMoveFocus ( FocusNavigationDirection . Right ) ;
457
445
}
@@ -466,14 +454,13 @@ private void Keyboard_KeyUp(object sender, KeyRoutedEventArgs e)
466
454
internal void OnPointerWheelChanged ( object sender , PointerRoutedEventArgs e )
467
455
{
468
456
var index = e . GetCurrentPoint ( null ) . Properties . MouseWheelDelta > 0 ? - 1 : 1 ;
469
- if ( index == - 1 && SelectedIndex > 0 )
457
+ if ( index == - 1 )
470
458
{
471
- SelectedIndex -- ;
459
+ BoundDecrement ( ) ;
472
460
}
473
-
474
- if ( index == 1 && SelectedIndex < Items . Count - 1 )
461
+ else if ( index == 1 )
475
462
{
476
- SelectedIndex ++ ;
463
+ BoundIncrement ( ) ;
477
464
}
478
465
479
466
e . Handled = true ;
@@ -547,5 +534,27 @@ internal void SetSelectedItem(CarouselItem owner)
547
534
var item = ItemFromContainer ( owner ) ;
548
535
SelectedItem = item ;
549
536
}
537
+
538
+ private bool BoundIncrement ( )
539
+ {
540
+ if ( SelectedIndex < Items . Count - 1 )
541
+ {
542
+ SelectedIndex ++ ;
543
+ return true ;
544
+ }
545
+
546
+ return false ;
547
+ }
548
+
549
+ private bool BoundDecrement ( )
550
+ {
551
+ if ( SelectedIndex > 0 )
552
+ {
553
+ SelectedIndex -- ;
554
+ return true ;
555
+ }
556
+
557
+ return false ;
558
+ }
550
559
}
551
- }
560
+ }
0 commit comments