/// <summary> /// Creates a new tab with the specified title which will be /// associated with the specified index of the specified <see cref="TabContainerView"/>. /// </summary> /// <param name="tabView">The <see cref="TabContainerView"/> the tab is created for.</param> /// <param name="title">The displayed title of the tab.</param> /// <param name="index">The index of the container to show when the tab is selected.</param> /// <returns>A <see cref="Label"/> representing the newly created tab.</returns> private static View CreateTab(TabContainerView tabView, string title, int index) { var lbl = new Label { Text = title, VerticalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.FillAndExpand, HorizontalTextAlignment = TextAlignment.Center, Margin = new Thickness(6, 0) }; lbl.SetDynamicResource(StyleProperty, "TitleStyle"); // change tab on click var gestureRecognizer = new TapGestureRecognizer(); gestureRecognizer.Tapped += (s, e) => { tabView.CurrentTab = $"{index}"; }; lbl.GestureRecognizers.Add(gestureRecognizer); return(lbl); }
/// <summary> /// Sets the currently displayed view by index. /// </summary> /// <param name="control">The instance of the <see cref="TabContainerView"/>.</param> /// <param name="index">The index to set.</param> private static void SetDisplayedView(TabContainerView control, int index) { if (control == null || index < 0 || index >= control.TabViews.Count) { throw new ArgumentException("Illegal arguments passed."); } control.contentContainer.Content = control.TabViews[index]; }