Skip to content

Instantly share code, notes, and snippets.

@chrisriesgo
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrisriesgo/6a5bc0f838c366cb3815 to your computer and use it in GitHub Desktop.
Save chrisriesgo/6a5bc0f838c366cb3815 to your computer and use it in GitHub Desktop.
void ItemsSourceChanged ()
{
if (ItemsSource == null) return;
CreateTabs();
}
void CreateTabs()
{
if(Children != null && Children.Count > 0) Children.Clear();
foreach(var item in ItemsSource)
{
var index = Children.Count;
var tab = new StackLayout {
Orientation = StackOrientation.Vertical,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Padding = new Thickness(7),
};
Device.OnPlatform(
iOS: () =>
{
tab.Children.Add(new Image { Source = "pin.png", HeightRequest = 20 });
tab.Children.Add(new Label { Text = "Tab " + (index + 1), FontSize = 11 });
},
Android: () =>
{
tab.Children.Add(new Image { Source = "pin.png", HeightRequest = 25 });
}
);
var tgr = new TapGestureRecognizer();
tgr.Command = new Command(() =>
{
SelectedItem = ItemsSource[index];
});
tab.GestureRecognizers.Add(tgr);
Children.Add(tab, index, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment