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() });
}
} |