/// <summary> /// Initializes a new instance of the <see cref="NControl.Controls.TabStripControl"/> class. /// </summary> public TabStripControl () { _mainLayout = new RelativeLayout (); Content = _mainLayout; // Create tab control _buttonStack = new StackLayoutEx { Orientation = StackOrientation.Horizontal, Padding = 0, Spacing = 0, HorizontalOptions = LayoutOptions.Start, VerticalOptions= LayoutOptions.FillAndExpand, }; _indicator = new TabBarIndicator { VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.Start, BackgroundColor = (Color)TabIndicatorColorProperty.DefaultValue, HeightRequest = 6, WidthRequest = 0, }; _tabControl = new NControlView{ BackgroundColor = TabBackColor, Content = new Grid{ Padding = 0, ColumnSpacing = 0, RowSpacing=0, Children = { _buttonStack, _indicator, } } }; _mainLayout.Children.Add (_tabControl, () => new Rectangle ( 0, 0, _mainLayout.Width, TabHeight) ); // Create content control _contentView = new Grid { ColumnSpacing = 0, RowSpacing = 0, Padding = 0, BackgroundColor = Color.Transparent, }; _mainLayout.Children.Add (_contentView, () => new Rectangle ( 0, TabHeight, _mainLayout.Width, _mainLayout.Height-TabHeight) ); _children.CollectionChanged += (sender, e) => { _contentView.Children.Clear(); _buttonStack.Children.Clear(); foreach(var tabChild in Children) { var tabItemControl = new TabBarButton(tabChild.Title); if(FontFamily != null) tabItemControl.FontFamily = FontFamily; tabItemControl.FontSize = FontSize; tabItemControl.SelectedColor = TabIndicatorColor; _buttonStack.Children.Add(tabItemControl); } if(Children.Any()) Activate(Children.First(), false); }; // Border var border = new NControlView { DrawingFunction = (canvas, rect) => { canvas.DrawPath (new NGraphics.PathOp[]{ new NGraphics.MoveTo(0, 0), new NGraphics.LineTo(rect.Width, 0) }, NGraphics.Pens.Gray, null); }, }; _mainLayout.Children.Add (border, () => new Rectangle( 0, TabHeight, _mainLayout.Width, 1)); // Shadow _shadow = new NControlView { DrawingFunction = (canvas, rect)=> { canvas.DrawRectangle(rect, null, new NGraphics.LinearGradientBrush( new NGraphics.Point(0.5, 0.0), new NGraphics.Point(0.5, 1.0), Color.Black.MultiplyAlpha(0.3).ToNColor(), NGraphics.Colors.Clear, NGraphics.Colors.Clear)); } }; _mainLayout.Children.Add (_shadow, () => new Rectangle( 0, TabHeight, _mainLayout.Width, 6)); _shadow.IsVisible = false; SizeChanged += (object sender, EventArgs e) => { _buttonStack.ForceLayout(); ForceLayout(); }; }
/// <summary> /// Initializes a new instance of the <see cref="NControl.Controls.TabStripControl"/> class. /// </summary> public TabStripControl() { _mainLayout = new RelativeLayout(); Content = _mainLayout; // Create tab control _buttonStack = new StackLayoutEx { Orientation = StackOrientation.Horizontal, Padding = 0, Spacing = 0, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.FillAndExpand, }; _indicator = new TabBarIndicator { VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.Start, BackgroundColor = (Color)TabIndicatorColorProperty.DefaultValue, HeightRequest = 6, WidthRequest = 0, }; _tabControl = new NControlView { BackgroundColor = TabBackColor, Content = new Grid { Padding = 0, ColumnSpacing = 0, RowSpacing = 0, Children = { _buttonStack, _indicator, } } }; _mainLayout.Children.Add(_tabControl, () => new Rectangle( 0, 0, _mainLayout.Width, TabHeight) ); // Create content control _contentView = new Grid { ColumnSpacing = 0, RowSpacing = 0, Padding = 0, BackgroundColor = Color.Transparent, }; _mainLayout.Children.Add(_contentView, () => new Rectangle( 0, TabHeight, _mainLayout.Width, _mainLayout.Height - TabHeight) ); _children.CollectionChanged += (sender, e) => { _contentView.Children.Clear(); _buttonStack.Children.Clear(); foreach (var tabChild in Children) { var tabItemControl = new TabBarButton(tabChild.Title); if (FontFamily != null) { tabItemControl.FontFamily = FontFamily; } tabItemControl.FontSize = FontSize; tabItemControl.SelectedColor = TabIndicatorColor; _buttonStack.Children.Add(tabItemControl); } if (Children.Any()) { Activate(Children.First(), false); } }; // Border var border = new NControlView { DrawingFunction = (canvas, rect) => { canvas.DrawPath(new NGraphics.PathOp[] { new NGraphics.MoveTo(0, 0), new NGraphics.LineTo(rect.Width, 0) }, NGraphics.Pens.Gray, null); }, }; _mainLayout.Children.Add(border, () => new Rectangle( 0, TabHeight, _mainLayout.Width, 1)); // Shadow _shadow = new NControlView { DrawingFunction = (canvas, rect) => { canvas.DrawRectangle(rect, null, new NGraphics.LinearGradientBrush( new NGraphics.Point(0.5, 0.0), new NGraphics.Point(0.5, 1.0), Color.Black.MultiplyAlpha(0.3).ToNColor(), NGraphics.Colors.Clear, NGraphics.Colors.Clear)); } }; _mainLayout.Children.Add(_shadow, () => new Rectangle( 0, TabHeight, _mainLayout.Width, 6)); _shadow.IsVisible = false; SizeChanged += (object sender, EventArgs e) => { _buttonStack.ForceLayout(); ForceLayout(); }; }