- Programmatically set selected index
- Selection indicator placements
- Customize selected segment
- Notifying segment selection changes
Contact Support
Selection in .NET MAUI Segmented Control (SfSegmentedControl)
This section describes the features of the Segmented Control that help with item selection, customization of the selected item, and associated operations.
Programmatically set selected index
Programmatically set the default value for the selection to be placed. The selection is updated based on the given index value for the SelectedIndex.
<ContentPage
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons">
<buttons:SfSegmentedControl x:Name="segmentedControl"
SelectedIndex="1">
</buttons:SfSegmentedControl>
</ContentPage>
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
segmentedControl.SelectedIndex = 1;
this.Content = segmentedControl;
}
}
Selection indicator placements
The Segmented control provides four types of selection indicator placement: Fill, border, top, and bottom border.
Fill
The selection indicator will fill the selected segment, if the SelectionIndicatorPlacement property of SelectionIndicatorSettings is set to Fill.
<ContentPage
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons">
<buttons:SfSegmentedControl x:Name="segmentedControl">
<buttons:SfSegmentedControl.SelectionIndicatorSettings>
<buttons:SelectionIndicatorSettings
SelectionIndicatorPlacement="Fill"/>
</buttons:SfSegmentedControl.SelectionIndicatorSettings>
</buttons:SfSegmentedControl>
</ContentPage>
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
segmentedControl.SelectionIndicatorSettings = new SelectionIndicatorSettings()
{
SelectionIndicatorPlacement = SelectionIndicatorPlacement.Fill,
};
this.Content = segmentedControl;
}
}
Border
The selection indicator will be highlighted with the border of the selected segment, if the SelectionIndicatorPlacement property of SelectionIndicatorSettings is set to Border.
<ContentPage
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons">
<buttons:SfSegmentedControl x:Name="segmentedControl">
<buttons:SfSegmentedControl.SelectionIndicatorSettings>
<buttons:SelectionIndicatorSettings
SelectionIndicatorPlacement="Border"/>
</buttons:SfSegmentedControl.SelectionIndicatorSettings>
</buttons:SfSegmentedControl>
</ContentPage>
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
segmentedControl.SelectionIndicatorSettings = new SelectionIndicatorSettings()
{
SelectionIndicatorPlacement = SelectionIndicatorPlacement.Border,
};
this.Content = segmentedControl;
}
}
Top border
The selection indicator will be placed at the top of the selected segment, if the SelectionIndicatorPlacement property of SelectionIndicatorSettings is set to TopBorder.
<ContentPage
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons">
<buttons:SfSegmentedControl x:Name="segmentedControl">
<buttons:SfSegmentedControl.SelectionIndicatorSettings>
<buttons:SelectionIndicatorSettings
SelectionIndicatorPlacement="TopBorder"/>
</buttons:SfSegmentedControl.SelectionIndicatorSettings>
</buttons:SfSegmentedControl>
</ContentPage>
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
segmentedControl.SelectionIndicatorSettings = new SelectionIndicatorSettings()
{
SelectionIndicatorPlacement = SelectionIndicatorPlacement.TopBorder,
};
this.Content = segmentedControl;
}
}
Bottom border
The selection indicator will be placed at the bottom of the selected segment, if the SelectionIndicatorPlacement property of SelectionIndicatorSettings is set to BottomBorder.
<ContentPage
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons">
<buttons:SfSegmentedControl x:Name="segmentedControl">
<buttons:SfSegmentedControl.SelectionIndicatorSettings>
<buttons:SelectionIndicatorSettings
SelectionIndicatorPlacement="BottomBorder"/>
</buttons:SfSegmentedControl.SelectionIndicatorSettings>
</buttons:SfSegmentedControl>
</ContentPage>
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
segmentedControl.SelectionIndicatorSettings = new SelectionIndicatorSettings()
{
SelectionIndicatorPlacement = SelectionIndicatorPlacement.BottomBorder,
};
this.Content = segmentedControl;
}
}
Customize selected segment
The selected segment of the Segmented control is customized using the SelectionIndicatorSettings property of SfSegmentedControl.
Customize selected segment background
You can customize the selected segment background of the segmented control and each segment item.
Customize selected segment background of segmented control
Customize the selected segment background using the Background property of SelectionIndicatorSettings.
<ContentPage
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons">
<buttons:SfSegmentedControl x:Name="segmentedControl">
<buttons:SfSegmentedControl.SelectionIndicatorSettings>
<buttons:SelectionIndicatorSettings
SelectionIndicatorPlacement="Fill"
Background="Blue"/>
</buttons:SfSegmentedControl.SelectionIndicatorSettings>
</buttons:SfSegmentedControl>
</ContentPage>
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
segmentedControl.SelectionIndicatorSettings = new SelectionIndicatorSettings()
{
SelectionIndicatorPlacement = SelectionIndicatorPlacement.Fill,
Background = Colors.Blue,
};
this.Content = segmentedControl;
}
}
NOTE
The
Background
property ofSelectionIndicatorSettings
is applicable only for SelectionIndicatorPlacement.Fill.
Customize selected segment background of each segment item
Customize the selected segment background of each segment item using the SelectedSegmentBackground property of SfSegmentItem.
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
List<SfSegmentItem> segmentItems = new List<SfSegmentItem>
{
new SfSegmentItem() {Text="Day", SelectedSegmentBackground = Colors.LightBlue},
new SfSegmentItem() {Text="Week", SelectedSegmentBackground = Colors.Blue},
new SfSegmentItem() {Text="Month", SelectedSegmentBackground = Colors.SkyBlue},
new SfSegmentItem() {Text="Year", SelectedSegmentBackground = Colors.DarkBlue},
};
segmentedControl.ItemsSource = segmentItems;
this.Content = segmentedControl;
}
}
Customize selected segment text color
You can customize the selected segment text color of the segmented control and each segment item.
Customize selected segment text color of segmented control
Customize the selected segment text color using the TextColor property of SelectionIndicatorSettings.
<ContentPage
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons">
<buttons:SfSegmentedControl x:Name="segmentedControl">
<buttons:SfSegmentedControl.SelectionIndicatorSettings>
<buttons:SelectionIndicatorSettings
TextColor="Red"/>
</buttons:SfSegmentedControl.SelectionIndicatorSettings>
</buttons:SfSegmentedControl>
</ContentPage>
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
segmentedControl.SelectionIndicatorSettings = new SelectionIndicatorSettings()
{
TextColor = Colors.Red,
};
this.Content = segmentedControl;
}
}
Customize selected segment text color of each segment item
Customize the selected segment text color of each segment item using the SelectedSegmentTextColor property of SfSegmentItem.
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
List<SfSegmentItem> segmentItems = new List<SfSegmentItem>
{
new SfSegmentItem() {Text="Day", SelectedSegmentTextColor = Colors.LightBlue},
new SfSegmentItem() {Text="Week", SelectedSegmentTextColor = Colors.Blue},
new SfSegmentItem() {Text="Month", SelectedSegmentTextColor = Colors.SkyBlue},
new SfSegmentItem() {Text="Year", SelectedSegmentTextColor = Colors.DarkBlue},
};
segmentedControl.ItemsSource = segmentItems;
this.Content = segmentedControl;
}
}
Customize selected segment border color
Customize the selected segment border color using the Stroke property of SelectionIndicatorSettings.
<ContentPage
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons">
<buttons:SfSegmentedControl x:Name="segmentedControl">
<buttons:SfSegmentedControl.SelectionIndicatorSettings>
<buttons:SelectionIndicatorSettings
SelectionIndicatorPlacement="BottomBorder"
Stroke="DodgerBlue"/>
</buttons:SfSegmentedControl.SelectionIndicatorSettings>
</buttons:SfSegmentedControl>
</ContentPage>
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
segmentedControl.SelectionIndicatorSettings = new SelectionIndicatorSettings()
{
SelectionIndicatorPlacement = SelectionIndicatorPlacement.BottomBorder,
Stroke = Colors.DodgerBlue,
};
this.Content = segmentedControl;
}
}
NOTE
The
Stroke
property ofSelectionIndicatorSettings
is applicable only when the selection mode is set to SelectionIndicatorPlacement.Border, SelectionIndicatorPlacement.TopBorder, or SelectionIndicatorPlacement.BottomBorder.
Customize selected segment border thickness
Customize the selected segment border thickness using the StrokeThickness property of SelectionIndicatorSettings.
<ContentPage
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons">
<buttons:SfSegmentedControl x:Name="segmentedControl">
<buttons:SfSegmentedControl.SelectionIndicatorSettings>
<buttons:SelectionIndicatorSettings
SelectionIndicatorPlacement="BottomBorder"
StrokeThickness="5"/>
</buttons:SfSegmentedControl.SelectionIndicatorSettings>
</buttons:SfSegmentedControl>
</ContentPage>
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
segmentedControl.SelectionIndicatorSettings = new SelectionIndicatorSettings()
{
SelectionIndicatorPlacement = SelectionIndicatorPlacement.BottomBorder,
StrokeThickness = 5,
};
this.Content = segmentedControl;
}
}
Notifying segment selection changes
The SelectionChanged event is triggered once the segment is selected in the segmented control. The SelectionChangedEventArgs has the following values, which provide information for the SelectionChanged
event.
- OldIndex
- NewIndex
- OldValue
- NewValue
using Syncfusion.Maui.Buttons;
. . .
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
SfSegmentedControl segmentedControl = new SfSegmentedControl();
segmentedControl.SelectionChanged += OnSegmentedControlSelectionChanged;
this.Content = segmentedControl;
}
private void OnSegmentedControlSelectionChanged(object sender, Syncfusion.Maui.Buttons.SelectionChangedEventArgs e)
{
var newValue = e.NewValue;
var oldValue = e.OldValue;
var newIndex = e.NewIndex;
var oldIndex = e.OldIndex;
}
}