Need help with Plugin.SegmentedControl?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

1iveowl
161 Stars 30 Forks MIT License 208 Commits 22 Opened issues

Services available

!
?

Need anything else?

Contributors list

# 77,998
C#
mqtt-pr...
mqtt-cl...
netfram...
107 commits
# 143,187
Xamarin
Univers...
wp
c-sharp
3 commits
# 257,598
Erlang
C++
big-sur
today-w...
1 commit
# 56,334
Xamarin
C#
xamarin...
xamarin...
1 commit
# 353,500
F#
interop
java-8
Clojure
1 commit
# 91,660
netfram...
iot-fra...
xamarin...
linq
1 commit

Plugin Segmented Control for Xamarin Forms and .NET Standard

NuGet Badge

Please star this project if you find it useful. Thank you!

Update - Version 5.2+

Version 5.2 and forward migrated to AndroidX for Android.

Update - Version 5.4.5+ (PR: #101)

ItemsSource is now of type IEnumerable instead of IList. It can contains full objects. When it contains a list of full object, the text displayed in a segment is read from a property on each object: define this property using TextPropertyName.

TextPropertyName
: string, name of a property in an
ItemsSource[i]
object. If
TextPropertyName
is set, the displayed text is read from this property on each source object. If
TextPropertyName
is not set, ItemsSource must be a list of string.

New property:

SelectedItem
SelectedItem = Items[SelectedSegment]
SelectedItem
contains the current selected object from
ItemsSource
.

Fix:

Remove the extra padding below the control on Android, caused by the wrong usage of match_parent.

Why this library?

There are other Segmented Control libraries out there. This library adds two important capabilities: - It works across all four key platforms: iOS, Android, macOS, and UWP - all other libraries I've encounted lack UWP and/or macOS. - It's based on .NET Standard 2.0

Furthermore, this library is has more flexibility and features than other libraries that I'm aware of.

Enjoy! And please don't forget to star this project if you find it useful and/or provide feedback if you run into issues or shortcomings.

Supported platforms

|Platform|Supported|Version|Renderer| | ------------------- | :-----------: | :-----------: | :------------------: | |Xamarin.iOS Unified|Yes|iOS 8.1+|UISegmentedControl| |Xamarin.Android|Yes|API 21+|RadioGroup| |Xamarin.UWP|Yes|Win10 16299+|User Control/RadioButton| |Xamarin.MacOS|Partial|10.0+|NSSegmentedControl|

Features

  • Bindable Tint color
  • Bindable Select color
  • Bindable Text color
  • Bindable Disabled color
  • Bindable Font size
  • Bindable Font Family
  • Bindable Item Text
  • Bindable Selected Item
  • Bindable ICommand
  • Bindable IsEnabled Item
  • Bindable ItemsSource
  • Bindable Border color (Android & iOS only)
  • Bindable Border width (Android & iOS only)

For more details please see below or for even more details see: Test/Demo App

How to use

Using this plugin is easy.

iOS

Add initializer to

AppDelegate
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();

Plugin.Segmented.Control.iOS.SegmentedControlRenderer.Initialize();
...

}

UWP

You need to add the assembly to App.xaml.cs in you project. For more details see the Xamarin documentation here.

var assembliesToInclude = new List {typeof(Plugin.Segmented.Control.UWP.SegmentedControlRenderer).GetTypeInfo().Assembly};

Xamarin.Forms.Forms.Init(e, assembliesToInclude);

Android

No special needs.

For using custom fonts with Android see this blog post: https://blog.verslu.is/xamarin/xamarin-forms-xamarin/custom-fonts-with-xamarin-forms-revisited/

.NET Standard

The Xamarin Forms must use .NET Standard. I suggest using .NET Standard 2.0+.

Here is a great blog post about how to move your PCL to .NET Standard: Building Xamarin.Forms Apps with .NET Standard

XAML

Plugin Segmented Control Picture

<contentpage.resources>
    <onplatform x:key="PlatformFontName" x:typearguments="x:String">
        <on platform="UWP" value="Courier New"></on>
        <on platform="Android" value="Serif"></on>
        <on platform="iOS" value="Helvetica"></on>
        <on platform="macOS" value="Baskerville"></on>
    </onplatform>
</contentpage.resources>

<contentpage.content>
    <stacklayout backgroundcolor="White" x:name="SegmentWithStack">
        <label text="Welcome to Xamarin.Forms!" horizontaloptions="CenterAndExpand"></label>
        <segmentedcontrol x:name="SegmentedControl" selectedsegment="{Binding SelectedSegment, Mode=TwoWay}" tintcolor="BlueViolet" selectedtextcolor="White" disabledcolor="Gray" bordercolor="Black" borderwidth="2.0" fontsize="Small" fontfamily="{StaticResource PlatformFontName}" margin="8,8,8,8" segmentselectedcommand="{Binding SegmentChangedCommand}" onelementchildrenchanging="OnElementChildrenChanging" itemssource="{Binding SegmentStringSource}">
            <!--<control:SegmentedControl.Children>
                <control:SegmentedControlOption Text="{Binding ChangeText}"/>
                <control:SegmentedControlOption Text="Item 2"/>
                <control:SegmentedControlOption Text="Item 3"/>
                <control:SegmentedControlOption Text="Item 4"/>
            </control:SegmentedControl.Children>-->
        </segmentedcontrol>
    </stacklayout>
</contentpage.content>

You can bind to the SegmentSelectedCommand for notification in your view model when a segment change has occurred.

xml
   

Credits

For inspiration and for the Android and iOS part I'd like to thank Alex Rainman for his great work on SegmentedControl.FormsPlugin.

Thank you to rjantz3 for adding much requested features and enhancements. Thank you to Thomas Kälin for critical Android and iOS fixes and improvements.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.