protected override void OnPropertyChanged(string propertyName = null) { if (!isSettingContent && propertyName == "Content") { throw new InvalidOperationException("Cannot set Content of TabLayout"); } if (propertyName == "SelectedIndex") { if (oldSelectedIndex > -1 && this.Children.Count > oldSelectedIndex) { var oldTab = this.Children.ElementAt(oldSelectedIndex); oldTab.SetSelected(false); } if (SelectedIndex > -1 && this.Children.Count > SelectedIndex) { var newTab = this.Children.ElementAt(SelectedIndex); newTab.SetSelected(true); this.TabContentView.RaiseChild(newTab); } SetTabChildrenBackground(); } else if (propertyName == "ScrollEnabled") { var stackLayout = (StackLayout)this.Content; stackLayout.Children.RemoveAt(0); View view; if (ScrollEnabled) { view = new HorizontalScrollView { Padding = 0, Orientation = ScrollOrientation.Horizontal, Content = this.GridView }; CurrentScrollView = view as HorizontalScrollView; CurrentScrollView.Padding = new Thickness(130, 0, 130, 0); } else { view = this.GridView; CurrentScrollView = null; } stackLayout.Children.Insert(0, view); } switch (propertyName) { case "BackgroundColor": case "SelectedBackgroundColor": case "SelectedBackgroundImage": SetTabChildrenBackground(); break; case "BackgroundImage": SetTabChildrenBackground(); break; case "TabHeight": tabHeight.Height = new GridLength(this.TabHeight); break; } base.OnPropertyChanged(propertyName); }
public TabLayout() { this.GridView = new Grid { HorizontalOptions = LayoutOptions.FillAndExpand, RowSpacing = 0, }; this.GridView.SetBinding(Grid.ColumnSpacingProperty, new Binding(path: "TabSpacing", source: this)); this.VerticalOptions = LayoutOptions.FillAndExpand; this.HorizontalOptions = LayoutOptions.FillAndExpand; this.Padding = 0; TabContentView = new Grid { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, RowSpacing = 0 }; TabContentView.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); TabContentView.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); View view = null; if (ScrollEnabled) { view = new HorizontalScrollView { Padding = 0, Orientation = ScrollOrientation.Horizontal, Content = this.GridView }; CurrentScrollView = view as HorizontalScrollView; } else { view = this.GridView; } var box = new BoxView(); box.SetBinding(BoxView.HeightRequestProperty, new Binding() { Source = this, Path = "SeparatorHeight" }); box.SetBinding(BoxView.ColorProperty, new Binding() { Source = this, Path = "LineColor" }); var box1 = new BoxView(); box1.SetBinding(BoxView.HeightRequestProperty, new Binding() { Source = this, Path = "SeparatorHeight" }); box1.SetBinding(BoxView.ColorProperty, new Binding() { Source = this, Path = "LineColor" }); //this.GridView.Children.Add(box, idx, 1); isSettingContent = true; var contentLayout = new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Orientation = StackOrientation.Vertical, Padding = 0, Spacing = 0, Children = { box, view, box1 }, }; TabContentView.Children.Add(contentLayout, 0, 0); this.Content = TabContentView; isSettingContent = false; tabHeight = new RowDefinition(); tabHeight.Height = new GridLength(this.TabHeight); //tabHeight.SetBinding(RowDefinition.HeightProperty, new Binding { Source = this, Path = "HeightRequest" }); //this.GridView.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); this.GridView.RowDefinitions.Add(tabHeight); var lineRow = new RowDefinition(); lineRow.SetBinding(RowDefinition.HeightProperty, new Binding { Source = this, Path = "LineHeight" }); //this.GridView.RowDefinitions.Add(lineRow); //this.GridView.ColumnSpacing = 0; //this.GridView.RowSpacing = 0; _tabChildren.CollectionChanged += _tabChildren_CollectionChanged; // TODO: implement XChanged as an event from listview //Resolver.Get<IScrollListener>().XChanged += TabLayout_XChanged; }