How to clear the segment selection in Xamarin.Forms SegmentedControl?
Xamarin.Forms SegmentedControl allows you to programmatically clear the selection by applying the negative value to the SelectedIndex.
Consider the use case to reset the segment selection by clicking the button as follows,
[XAML]
.. <buttons:SfSegmentedControl x:Name="segment" SelectionTextColor="White" HeightRequest="80" VisibleSegmentsCount="6" Color="Transparent" BorderColor="Black" SelectedIndex="1" FontColor="Black" BackgroundColor="Transparent" > <segmentCollection:List x:TypeArguments="x:String"> <x:String>RedMi</x:String> <x:String>oppo</x:String> <x:String>vivo</x:String> <x:String>ipad</x:String> <x:String>realme</x:String> <x:String>Nokia</x:String> </segmentCollection:List> </buttons:SfSegmentedControl> <Button Text="Button" Clicked="Button_Clicked" WidthRequest="150"/> ..
[C#]
private void Button_Clicked(object sender, EventArgs e) { segment.SelectedIndex = -1; }
Output
See Also
How to add images in the Xamarin.Forms SegmentedControl
How to create a SegmentedControl with custom view
How to customize the segmented item with custom font
Conclusion
I hope you enjoyed learning about how to clear the segment selection in Xamarin.Forms SegmentedControl.
You can refer to our Xamarin.Forms SegmentedControl feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!