Skip to content

simyco/SegmentedControl

 
 

Repository files navigation

Segmented Control Plugin for Xamarin Forms

Setup

Platform Support

Platform Supported Version Renderer
Xamarin.iOS Unified Yes iOS 8.1+ UISegmentedControl
Xamarin.Android Yes API 15+ RadioGroup

Usage

In your iOS and Android projects call:

Xamarin.Forms.Init();
CarouselViewRenderer.Init();

XAML

xmlns:controls="clr-namespace:SegmentedControl.FormsPlugin.Abstractions;assembly=SegmentedControl.FormsPlugin.Abstractions"
<controls:SegmentedControl x:Name="SegControl" TintColor="#007AFF" SelectedSegment="0" ValueChanged="Handle_ValueChanged">
  <controls:SegmentedControl.Children>
    <controls:SegmentedControlOption Text="Tab 1" />
    <controls:SegmentedControlOption Text="Tab 2" />
    <controls:SegmentedControlOption Text="Tab 3" />
    <controls:SegmentedControlOption Text="Tab 4" />
  </controls:SegmentedControl.Children>
</controls:SegmentedControl>
<StackLayout x:Name="SegContent" Grid.Row="1" Grid.Column="0">
</StackLayout>

Event handler

public void Handle_ValueChanged(object o, EventArgs e)
{
	SegContent.Children.Clear();

	switch (SegControl.SelectedSegment)
	{
		case 0:
			SegContent.Children.Add(new Label() { Text="Tab 1 selected" });
			break;
		case 1:
			SegContent.Children.Add(new Label() { Text = "Tab 2 selected" });
			break;
		case 2:
			SegContent.Children.Add(new Label() { Text = "Tab 3 selected" });
			break;
		case 3:
			SegContent.Children.Add(new Label() { Text = "Tab 4 selected" });
			break;
	}
}

Bindable Properties

TintColor: Fill color for the control (Color, default #007AFF)

SelectedSegment: Selected segment index (int, default 0).

Event Handlers

ValueChanged: Called when a segment is selected.

Contributors

Thanks!

License

Licensed under repo license

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%