Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
149853 | Dec 11,2019 04:18 PM UTC | Dec 13,2019 04:50 AM UTC | Xamarin.Forms | 3 |
![]() |
Tags: SfSegmentedControl |
public partial class MainPage : ContentPage
{
SfSegmentedControl stringSegmentControl;
SfSegmentedControl segmentControl;
public MainPage()
{
InitializeComponent();
StackLayout stackLayout = new StackLayout();
stringSegmentControl = new SfSegmentedControl()
{
ItemsSource = new ObservableCollection<string>() { "Segment 1", "Segment 2", "Segment 3" },
Margin = new Thickness(0, 40, 0, 0)
};
segmentControl = new SfSegmentedControl()
{
ItemsSource = new ObservableCollection<SfSegmentItem>()
{
new SfSegmentItem(){Text = "Segment 1"},
new SfSegmentItem(){Text = "Segment 2"},
new SfSegmentItem(){Text = "Segment 3"},
},
Margin = new Thickness(0, 40, 0, 0)
};
Button dynamicUpdate = new Button() { Text = "Click to Update" };
dynamicUpdate.Clicked += DynamicUpdate_Clicked;
stackLayout.Children.Add(stringSegmentControl);
stackLayout.Children.Add(segmentControl);
stackLayout.Children.Add(dynamicUpdate);
this.Content = stackLayout;
}
private void DynamicUpdate_Clicked(object sender, EventArgs e)
{
var stringCollection = (stringSegmentControl.ItemsSource as ObservableCollection<string>);
stringCollection.Add("Segment " + (stringCollection.Count + 1).ToString());
var segmentCollection = (segmentControl.ItemsSource as ObservableCollection<SfSegmentItem>);
segmentCollection.Add(new SfSegmentItem() { Text = "Segment " + (segmentCollection.Count + 1).ToString() });
}
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.