public TitleBar(Page page, BarBtnEnum barBtn = BarBtnEnum.bbNone, BarAlignEnum barAlign = BarAlignEnum.baTop) { NavigationPage.SetHasNavigationBar(page, false); NavigationPage.SetHasBackButton(page, false); page.Title = ""; page.Appearing += (s, e) => { NavigationPage.SetHasNavigationBar(page, false); }; page.Disappearing += (s, e) => { NavigationPage.SetHasNavigationBar(page, false); }; if ((Device.OS == TargetPlatform.iOS) && (barAlign == BarAlignEnum.baTop)) { PaddingBar = 20; } BackgroundColor = barColor; MinimumHeightRequest = HeightBar + PaddingBar; HeightRequest = HeightBar + PaddingBar; appBar.BackgroundColor = barColor; appBar.Padding = new Thickness(0, PaddingBar, 0, 0); appBar.MinimumHeightRequest = HeightRequest; appBar.HeightRequest = HeightRequest; boxPadding.BackgroundColor = barColor; #region Title create txtTitle = new Label { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand }; AbsoluteLayout.SetLayoutFlags(txtTitle, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(txtTitle, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize) ); appBar.Children.Add(txtTitle); #endregion #region Panel for left buttons var stackLeftBtn = new StackLayout { Padding = new Thickness(0), Spacing = 0, Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Start }; SetLayoutFlags(stackLeftBtn, AbsoluteLayoutFlags.PositionProportional); SetLayoutBounds(stackLeftBtn, new Rectangle(0, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); appBar.Children.Add(stackLeftBtn); #endregion #region Panel for right buttons var stackRightBtn = new StackLayout { Padding = new Thickness(0), Spacing = 0, Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.End }; AbsoluteLayout.SetLayoutFlags(stackRightBtn, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(stackRightBtn, new Rectangle(1, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); appBar.Children.Add(stackRightBtn); #endregion #region Back button BtnBack = new BackImageButton(page); BtnBack.WidthRequest = HeightBar; BtnBack.HeightRequest = HeightBar; if ((barBtn & BarBtnEnum.bbBack) != 0) { stackLeftBtn.Children.Add(BtnBack); } #endregion #region LeftLeft button BtnLeftLeft = new ImageButton(); BtnLeftLeft.WidthRequest = HeightBar; BtnLeftLeft.HeightRequest = HeightBar; if ((barBtn & BarBtnEnum.bbLeftLeft) != 0) { stackLeftBtn.Children.Add(BtnLeftLeft); } #endregion #region Left button BtnLeft = new ImageButton(); BtnLeft.WidthRequest = HeightBar; BtnLeft.HeightRequest = HeightBar; if (((barBtn & BarBtnEnum.bbLeft) != 0) || ((barBtn & BarBtnEnum.bbLeftLeft) != 0)) { stackLeftBtn.Children.Add(BtnLeft); } #endregion #region Right button BtnRight = new ImageButton(); BtnRight.WidthRequest = HeightBar; BtnRight.HeightRequest = HeightBar; if (((barBtn & BarBtnEnum.bbRight) != 0) || ((barBtn & BarBtnEnum.bbRightRight) != 0)) { stackRightBtn.Children.Add(BtnRight); } #endregion #region RightRight button BtnRightRight = new ImageButton(); BtnRightRight.WidthRequest = HeightBar; BtnRightRight.HeightRequest = HeightBar; if ((barBtn & BarBtnEnum.bbRightRight) != 0) { stackRightBtn.Children.Add(BtnRightRight); } #endregion AbsoluteLayout.SetLayoutFlags(appBar, AbsoluteLayoutFlags.All); AbsoluteLayout.SetLayoutBounds(appBar, new Rectangle(0f, 0f, 1f, 1f)); Children.Add(appBar); if ((Device.OS == TargetPlatform.iOS) && (barAlign == BarAlignEnum.baTop)) { AbsoluteLayout.SetLayoutFlags(boxPadding, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(boxPadding, new Rectangle(0, 0, 600, PaddingBar)); Children.Add(boxPadding); } }
public TitleBar(Page page, BarBtnEnum barBtn = BarBtnEnum.bbNone, BarAlignEnum barAlign = BarAlignEnum.baTop) { NavigationPage.SetHasNavigationBar(page, false); NavigationPage.SetHasBackButton(page, false); page.Title = ""; page.Appearing += (s, e) => { NavigationPage.SetHasNavigationBar(page, false); }; page.Disappearing += (s, e) => { NavigationPage.SetHasNavigationBar(page, false); }; if ((Device.OS == TargetPlatform.iOS) && (barAlign == BarAlignEnum.baTop)) PaddingBar = 20; BackgroundColor = barColor; MinimumHeightRequest = HeightBar + PaddingBar; HeightRequest = HeightBar + PaddingBar; appBar.BackgroundColor = barColor; appBar.Padding = new Thickness(0, PaddingBar, 0, 0); appBar.MinimumHeightRequest = HeightRequest; appBar.HeightRequest = HeightRequest; boxPadding.BackgroundColor = barColor; #region Title create txtTitle = new Label { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand }; AbsoluteLayout.SetLayoutFlags(txtTitle, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(txtTitle, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize) ); appBar.Children.Add(txtTitle); #endregion #region Panel for left buttons var stackLeftBtn = new StackLayout { Padding = new Thickness (0), Spacing = 0, Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Start }; SetLayoutFlags(stackLeftBtn, AbsoluteLayoutFlags.PositionProportional); SetLayoutBounds(stackLeftBtn, new Rectangle(0, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); appBar.Children.Add(stackLeftBtn); #endregion #region Panel for right buttons var stackRightBtn = new StackLayout { Padding = new Thickness(0), Spacing = 0, Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.End }; AbsoluteLayout.SetLayoutFlags(stackRightBtn, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(stackRightBtn, new Rectangle(1, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); appBar.Children.Add(stackRightBtn); #endregion #region Back button BtnBack = new BackImageButton(page); BtnBack.WidthRequest = HeightBar; BtnBack.HeightRequest = HeightBar; if ((barBtn & BarBtnEnum.bbBack) != 0) stackLeftBtn.Children.Add(BtnBack); #endregion #region LeftLeft button BtnLeftLeft = new ImageButton(); BtnLeftLeft.WidthRequest = HeightBar; BtnLeftLeft.HeightRequest = HeightBar; if ((barBtn & BarBtnEnum.bbLeftLeft) != 0) stackLeftBtn.Children.Add(BtnLeftLeft); #endregion #region Left button BtnLeft = new ImageButton(); BtnLeft.WidthRequest = HeightBar; BtnLeft.HeightRequest = HeightBar; if (((barBtn & BarBtnEnum.bbLeft) != 0) || ((barBtn & BarBtnEnum.bbLeftLeft) != 0)) stackLeftBtn.Children.Add(BtnLeft); #endregion #region Right button BtnRight = new ImageButton(); BtnRight.WidthRequest = HeightBar; BtnRight.HeightRequest = HeightBar; if (((barBtn & BarBtnEnum.bbRight) != 0) || ((barBtn & BarBtnEnum.bbRightRight) != 0)) stackRightBtn.Children.Add(BtnRight); #endregion #region RightRight button BtnRightRight = new ImageButton(); BtnRightRight.WidthRequest = HeightBar; BtnRightRight.HeightRequest = HeightBar; if ((barBtn & BarBtnEnum.bbRightRight) != 0) stackRightBtn.Children.Add(BtnRightRight); #endregion AbsoluteLayout.SetLayoutFlags(appBar, AbsoluteLayoutFlags.All); AbsoluteLayout.SetLayoutBounds(appBar, new Rectangle(0f, 0f, 1f, 1f)); Children.Add(appBar); if ((Device.OS == TargetPlatform.iOS) && (barAlign == BarAlignEnum.baTop)) { AbsoluteLayout.SetLayoutFlags(boxPadding, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(boxPadding, new Rectangle(0, 0, 600, PaddingBar)); Children.Add(boxPadding); } }