@@ -9,7 +9,7 @@ namespace Syncfusion.Maui.Toolkit.SegmentedControl
9
9
/// <summary>
10
10
/// Represents a view used to display an individual segment item within a segmented control.
11
11
/// </summary>
12
- internal partial class SegmentItemView : SfContentView , ITouchListener , ITapGestureListener
12
+ internal partial class SegmentItemView : SfContentView , ITouchListener , ITapGestureListener , IKeyboardListener
13
13
{
14
14
#region Fields
15
15
@@ -70,10 +70,15 @@ internal SegmentItemView(ISegmentItemInfo itemInfo, SfSegmentItem item)
70
70
InitializeEffectsView ( ) ;
71
71
this . AddTouchListener ( this ) ;
72
72
this . AddGestureListener ( this ) ;
73
+ #if WINDOWS
74
+ this . AddKeyboardListener ( this ) ;
75
+ #endif
73
76
if ( itemInfo ? . SegmentTemplate != null )
74
77
{
75
78
CreateSegmentItemTemplateView ( ) ;
76
79
}
80
+
81
+ UpdateSemantics ( ) ;
77
82
}
78
83
79
84
#endregion
@@ -107,6 +112,7 @@ internal void UpdateSelection()
107
112
_isSelected = true ;
108
113
_selectionView ? . UpdateVisualState ( true ) ;
109
114
InvalidateDrawable ( ) ;
115
+ UpdateSemantics ( ) ;
110
116
}
111
117
112
118
/// <summary>
@@ -123,6 +129,7 @@ internal void ClearSelection()
123
129
_isSelected = false ;
124
130
_selectionView . UpdateVisualState ( _isSelected , false ) ;
125
131
InvalidateDrawable ( ) ;
132
+ UpdateSemantics ( ) ;
126
133
}
127
134
128
135
/// <summary>
@@ -420,6 +427,9 @@ void InitializeImageView()
420
427
#endif
421
428
} ;
422
429
430
+ #if WINDOWS
431
+ AutomationProperties . SetIsInAccessibleTree ( _imageView , false ) ;
432
+ #endif
423
433
Children . Add ( _imageView ) ;
424
434
}
425
435
@@ -435,6 +445,9 @@ void InitializeSelectionView()
435
445
}
436
446
437
447
_selectionView = new SelectionView ( _segmentItem , itemInfo ) ;
448
+ #if WINDOWS
449
+ AutomationProperties . SetIsInAccessibleTree ( _selectionView , false ) ;
450
+ #endif
438
451
Children . Add ( _selectionView ) ;
439
452
}
440
453
@@ -453,6 +466,9 @@ void InitializeEffectsView()
453
466
_effectsView . ShouldIgnoreTouches = true ;
454
467
_effectsView . AnimationCompleted += OnEffectsViewAnimationCompleted ;
455
468
_effectsView . ClipToBounds = true ;
469
+ #if WINDOWS
470
+ AutomationProperties . SetIsInAccessibleTree ( _effectsView , false ) ;
471
+ #endif
456
472
Children . Add ( _effectsView ) ;
457
473
}
458
474
@@ -597,6 +613,28 @@ void RemoveEffects()
597
613
_effectsView . Reset ( ) ;
598
614
}
599
615
616
+ /// <summary>
617
+ /// Method to update the semantic properties.
618
+ /// </summary>
619
+ void UpdateSemantics ( )
620
+ {
621
+ if ( _segmentItem != null )
622
+ {
623
+ if ( ! string . IsNullOrEmpty ( SemanticProperties . GetDescription ( _segmentItem ) ) )
624
+ {
625
+ SemanticProperties . SetDescription ( this , SemanticProperties . GetDescription ( _segmentItem ) ) ;
626
+ }
627
+ else if ( ! _segmentItem . IsEnabled || ( itemInfo != null && ! itemInfo . IsEnabled ) )
628
+ {
629
+ SemanticProperties . SetDescription ( this , _segmentItem . Text + SfSegmentedResources . GetLocalizedString ( "Disabled" ) ) ;
630
+ }
631
+ else
632
+ {
633
+ SemanticProperties . SetDescription ( this , _isSelected ? _segmentItem . Text + SfSegmentedResources . GetLocalizedString ( "Selected" ) : _segmentItem . Text ) ;
634
+ }
635
+ }
636
+ }
637
+
600
638
/// <summary>
601
639
/// Method to remove the selection view handlers.
602
640
/// </summary>
@@ -746,7 +784,11 @@ protected override void OnDraw(ICanvas canvas, RectF dirtyRect)
746
784
semanticsNode . OnClick = OnSemanticsNodeClick ;
747
785
}
748
786
string text = _segmentItem . Text ;
749
- if ( ! _segmentItem . IsEnabled || ( itemInfo != null && ! itemInfo . IsEnabled ) )
787
+ if ( ! string . IsNullOrEmpty ( SemanticProperties . GetDescription ( _segmentItem ) ) )
788
+ {
789
+ semanticsNode . Text = SemanticProperties . GetDescription ( _segmentItem ) ;
790
+ }
791
+ else if ( ! _segmentItem . IsEnabled || ( itemInfo != null && ! itemInfo . IsEnabled ) )
750
792
{
751
793
semanticsNode . Text = text + SfSegmentedResources . GetLocalizedString ( "Disabled" ) ;
752
794
}
@@ -758,6 +800,21 @@ protected override void OnDraw(ICanvas canvas, RectF dirtyRect)
758
800
return [ semanticsNode ] ;
759
801
}
760
802
803
+ #if WINDOWS
804
+ /// <summary>
805
+ /// Raises when <see cref="SegmentItemView"/>'s handler gets changed.
806
+ /// <exclude/>
807
+ /// </summary>
808
+ protected override void OnHandlerChanged ( )
809
+ {
810
+ base . OnHandlerChanged ( ) ;
811
+ if ( this . Handler != null && this . Handler . PlatformView != null && this . Handler . PlatformView is Microsoft . UI . Xaml . UIElement nativeView )
812
+ {
813
+ nativeView . IsTabStop = true ;
814
+ }
815
+ }
816
+ #endif
817
+
761
818
/// <summary>
762
819
/// Measures the size of the view's content based on the specified constraints.
763
820
/// </summary>
@@ -875,6 +932,30 @@ void ITapGestureListener.OnTap(Syncfusion.Maui.Toolkit.Internals.TapEventArgs e)
875
932
#endif
876
933
}
877
934
935
+ /// <summary>
936
+ /// Gets a value indicating whether the view can become the first responder to listen the keyboard actions.
937
+ /// </summary>
938
+ /// <remarks>This property will be considered only in iOS Platform.</remarks>
939
+ bool IKeyboardListener . CanBecomeFirstResponder
940
+ {
941
+ get { return true ; }
942
+ }
943
+
944
+ /// <inheritdoc/>
945
+ void IKeyboardListener . OnKeyDown( KeyEventArgs e )
946
+ {
947
+ if ( e . Key == KeyboardKey . Enter )
948
+ {
949
+ UpdateSelectedIndex ( ) ;
950
+ }
951
+ }
952
+
953
+ /// <inheritdoc/>
954
+ void IKeyboardListener . OnKeyUp( KeyEventArgs args )
955
+ {
956
+
957
+ }
958
+
878
959
#endregion
879
960
}
880
961
}
0 commit comments