@@ -393,11 +393,8 @@ private void Keyboard_KeyUp(object sender, KeyRoutedEventArgs e)
393393                case  Windows . System . VirtualKey . GamepadLeftThumbstickDown : 
394394                    if  ( Orientation  ==  Orientation . Vertical ) 
395395                    { 
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 ) 
401398                        { 
402399                            FocusManager . TryMoveFocus ( FocusNavigationDirection . Down ) ; 
403400                        } 
@@ -411,11 +408,8 @@ private void Keyboard_KeyUp(object sender, KeyRoutedEventArgs e)
411408                case  Windows . System . VirtualKey . GamepadLeftThumbstickUp : 
412409                    if  ( Orientation  ==  Orientation . Vertical ) 
413410                    { 
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 ) 
419413                        { 
420414                            FocusManager . TryMoveFocus ( FocusNavigationDirection . Up ) ; 
421415                        } 
@@ -429,11 +423,8 @@ private void Keyboard_KeyUp(object sender, KeyRoutedEventArgs e)
429423                case  Windows . System . VirtualKey . GamepadLeftThumbstickLeft : 
430424                    if  ( Orientation  ==  Orientation . Horizontal ) 
431425                    { 
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 ) 
437428                        { 
438429                            FocusManager . TryMoveFocus ( FocusNavigationDirection . Left ) ; 
439430                        } 
@@ -447,11 +438,8 @@ private void Keyboard_KeyUp(object sender, KeyRoutedEventArgs e)
447438                case  Windows . System . VirtualKey . GamepadLeftThumbstickRight : 
448439                    if  ( Orientation  ==  Orientation . Horizontal ) 
449440                    { 
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 ) 
455443                        { 
456444                            FocusManager . TryMoveFocus ( FocusNavigationDirection . Right ) ; 
457445                        } 
@@ -466,14 +454,13 @@ private void Keyboard_KeyUp(object sender, KeyRoutedEventArgs e)
466454        internal  void  OnPointerWheelChanged ( object  sender ,  PointerRoutedEventArgs  e ) 
467455        { 
468456            var  index  =  e . GetCurrentPoint ( null ) . Properties . MouseWheelDelta  >  0  ?  - 1  :  1 ; 
469-             if  ( index  ==  - 1   &&   SelectedIndex   >   0 ) 
457+             if  ( index  ==  - 1 ) 
470458            { 
471-                 SelectedIndex -- ; 
459+                 BoundDecrement ( ) ; 
472460            } 
473- 
474-             if  ( index  ==  1  &&  SelectedIndex  <  Items . Count  -  1 ) 
461+             else  if  ( index  ==  1 ) 
475462            { 
476-                 SelectedIndex ++ ; 
463+                 BoundIncrement ( ) ; 
477464            } 
478465
479466            e . Handled  =  true ; 
@@ -547,5 +534,27 @@ internal void SetSelectedItem(CarouselItem owner)
547534            var  item  =  ItemFromContainer ( owner ) ; 
548535            SelectedItem  =  item ; 
549536        } 
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+         } 
550559    } 
551- } 
560+ } 
0 commit comments