Note: Migrating from Xamarin.Forms Issue 6904
Have a segmented control for Xamarin.Forms. iOS has UISegmentedControl, but Android does not. This control will provide native looking segments for Android platform.
iOS | Android
--|--
| 
|
|| 
The SegmentsView implements IList<string> with DisplayMode of Text or Image.
SegmentsView:
class SegmentsView : View {}
Name | Type | Description
---|---|---
Display Mode | Enum | Display mode is SegmentMode.Text by default and can be set to SegmentMode.Image as an alternative.
Color | Xamarin.Forms.Color | Main color for the control
Items | IList\
SelectedItem | object | Selected item
SelectedIndexChanged | Event | Event handler for when a segment is selected. Raises SelectedItemChangedEventArgs with segment and selected index
SelectedIndex | System.Int32 | Index of selected segment
Name | Type | Description
---|---|---
CornerRadius | double | Corner radius on Android ONLY
XAML
<SegmentsView SelectedIndexChanged="OnSegmentSelected">
<SegmentsView.Items>
<x:String>View A</x:String>
<x:String>View B</x:String>
</SegmentsView.Items>
</SegmentsView>
<!-- Using ItemsSource -->
<SegmentsView
SelectedIndexChanged="OnSegmentSelected"
ItemsSource="{Binding values}">
</SegmentsView>
C#
var segments = new SegmentView
{
Children = new List<string>
{
"View A",
"View B",
"View C"
}
};
segments.SelectedIndexChanged += OnSegmentSelected;
// handler
void OnSegmentSelected(object sender, SelectedItemChangedEventArgs e){ }
On iOS, this is simply a UISegmentedControl.
On Android, this is be a RadioGroup with a custom RadioButton that renders a simple text or bitmap drawable in image mode.
class FormsSegmentsView : Android.Widget.RadioGroup
馃憖 TBD
Enjoy! 馃憤
This would be a great addition to the XCT! @hnabbasi , could you also add something like a DisplayValueConverter? So we could potentially provide any kind of object in the ItemsSource and let this converter define the text value or image source value for each segment? If I could be of any assistance, please let me know 馃槉馃憣
This would be a great addition to the XCT! @hnabbasi , could you also add something like a DisplayValueConverter? So we could potentially provide any kind of object in the ItemsSource and let this converter define the text value or image source value for each segment? If I could be of any assistance, please let me know 馃槉馃憣
Good one. I have a private Display property that I can expose and use for that purpose. Just like the Picker does.
Exactly! That would be awesome! Thanks
Hey @jfversluis @PureWeen,
So, in Xamarin.Forms we had GetNativeImageAsync() extension to ImageSource. And GetNativeImageAsync() calls up the IImageSourceHandler's LoadImageAsync() on all possible sources.
I have a need for that handy extension for this control and I am wondering if I should recreate that whole suite of classes so future controls can also use the GetNativeImageAsync() or is there a way we can expose that in Xamarin.Forms.Internals so I can just reuse that? Thoughts
This would be awesome! 馃憣Only thing I don't like with the android version is that it misses animations when you change items :(
This would be awesome! 馃憣Only thing I don't like with the android version is that it misses animations when you change items :(
Good point 馃. Maybe I can work on it after I am done migrating over the Android version.