void toggleBackButtonText_Clicked(object sender, EventArgs e) { var page = Navigation.NavigationStack.First(); var titleText = NavigationPage.GetBackButtonTitle(page); if (titleText == null) { titleText = "Custom Text"; } else if (titleText == "Custom Text") { titleText = ""; } else { titleText = null; } NavigationPage.SetBackButtonTitle(page, titleText); changeTitleView_Clicked(this, EventArgs.Empty); string result = (titleText == null) ? "<null>" : titleText; btnToggleBackButtonTitle.Text = $"Toggle Back Button Title Text: {result}"; }
internal void UpdateNavigationItems(bool forceShowBackButton = false) { if (_toolbar == null || _navigation == null || _navigationGroup == null) { return; } var items = new List <ToolbarItem>(); if (ShowBackButton(forceShowBackButton)) { bool isBackButtonTextSet = _navigation.IsSet(NavigationPage.BackButtonTitleProperty); var backButtonTitle = isBackButtonTextSet ? NavigationPage.GetBackButtonTitle(_navigation) : GetPreviousPageTitle(); var backButtonItem = new ToolbarItem { Text = backButtonTitle, Command = new Command(async() => await NavigateBackFrombackButton()) }; items.Add(backButtonItem); } UpdateGroup(_navigationGroup, items); var navItemBack = _navigationGroup.Items.FirstOrDefault(); if (navItemBack != null) { navItemBack.Button.Image = NSImage.ImageNamed(NSImageName.GoLeftTemplate); navItemBack.Button.SizeToFit(); UpdateGroupWidth(_navigationGroup); navItemBack.Button.AccessibilityTitle = "NSBackButton"; } }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); var page = Element as BaseContentPage <BaseViewModel>; if (page == null) { return; } #region for soft back button var root = NavigationController.TopViewController; if (!page.NeedOverrideSoftBackButton) { return; } var title = NavigationPage.GetBackButtonTitle(Element); root.NavigationItem.SetLeftBarButtonItem( new UIBarButtonItem(title, UIBarButtonItemStyle.Plain, (sender, args) => { page.OnSoftBackButtonPressed(); }), true); #endregion }
private void Button_Clicked(object sender, System.EventArgs e) { var foo = NavigationPage.GetBackButtonTitle(this); NavigationPage.SetBackButtonTitle(this, "ddd"); //NavigationPage.SetHasNavigationBar(this, false); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); var page = Element as XFVNNavigationAnimationBasePageView; if (page == null) { return; } #region for soft back button var root = NavigationController.TopViewController; if (!page.NeedOverrideSoftBackButton) { return; } var title = "<" + (string.IsNullOrEmpty(NavigationPage.GetBackButtonTitle(Element)) ? "Back" : NavigationPage.GetBackButtonTitle(Element)); root.NavigationItem.SetLeftBarButtonItem( new UIBarButtonItem(title, UIBarButtonItemStyle.Plain, (sender, args) => { page.OnSoftBackButtonPressed(); }), true); #endregion }
ParentingViewController CreateViewControllerForPage(Page page) { if (Platform.GetRenderer(page) == null) { Platform.SetRenderer(page, Platform.CreateRenderer(page)); } // must pack into container so padding can work // otherwise the view controller is forced to 0,0 var pack = new ParentingViewController(this) { Child = page }; if (!string.IsNullOrWhiteSpace(page.Title)) { pack.NavigationItem.Title = page.Title; } // First page and we have a master detail to contend with UpdateLeftBarButtonItem(pack); //var pack = Platform.GetRenderer (view).ViewController; var titleIcon = NavigationPage.GetTitleIcon(page); if (!string.IsNullOrEmpty(titleIcon)) { try { //UIImage ctor throws on file not found if MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure is true; pack.NavigationItem.TitleView = new UIImageView(new UIImage(titleIcon)); } catch { } } var titleText = NavigationPage.GetBackButtonTitle(page); if (titleText != null) { // adding a custom event handler to UIBarButtonItem for navigating back seems to be ignored. pack.NavigationItem.BackBarButtonItem = new UIBarButtonItem { Title = titleText, Style = UIBarButtonItemStyle.Plain }; } var pageRenderer = Platform.GetRenderer(page); pack.View.AddSubview(pageRenderer.ViewController.View); pack.AddChildViewController(pageRenderer.ViewController); pageRenderer.ViewController.DidMoveToParentViewController(pack); return(pack); }
void UpdateBackButtonTitle() { string title = null; if (_previousPage != null) { title = NavigationPage.GetBackButtonTitle(_previousPage); } _container.BackButtonTitle = title; }
string GetBackButtonText() { if (_navigation == null || _navigation.StackDepth <= 1) { return(string.Empty); } var page = _navigation.Peek(1); return(NavigationPage.GetBackButtonTitle(page) ?? page.Title ?? _defaultBackButtonTitle); }
private void SetPageId(Page page) { if (page == null) { return; } var id = NavigationPage.GetBackButtonTitle(page); if (string.IsNullOrWhiteSpace(id)) { NavigationPage.SetBackButtonTitle(page, App.XenClassId); } }
public void SetPage(BaseContentPage basePage, BaseContentUI baseContentUI) { ViewPage = basePage; ContentUI = baseContentUI; Title = ContentUI.Title; appBarBackBtnTitle = NavigationPage.GetBackButtonTitle(ViewPage); InitProperty(); ViewPage.Appearing += ViewPage_Appearing; InitLifecycle(); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); if (!(Element is ModalNavigationPage element)) { return; } if (!(element.RootPage is ISoftNavigationPage page)) { return; } var title = $"<{(string.IsNullOrEmpty(NavigationPage.GetBackButtonTitle(Element)) ? BackTitle : NavigationPage.GetBackButtonTitle(Element))}"; TopViewController.NavigationItem.SetLeftBarButtonItem( new UIBarButtonItem(title, UIBarButtonItemStyle.Plain, (sender, args) => { if (!page.OnSoftBackButtonPressed()) { element.PopAsync(animated); } }), animated); }
public NavigationBarGallery(NavigationPage rootNavPage) { _rootNavPage = rootNavPage; int toggleBarTextColor = 0; int toggleBarBackgroundColor = 0; ToolbarItems.Add(new ToolbarItem { Text = "Save" }); NavigationPage.SetTitleIconImageSource(this, "coffee.png"); SearchBar searchBar = new SearchBar { HeightRequest = 44, WidthRequest = 100 }; // Note: Large and complex controls, such as ListView and TableView, are not recommended. var controls = new List <View> { searchBar, new ActivityIndicator { IsRunning = true }, new BoxView { BackgroundColor = Colors.Red }, new Button { Text = "Button!" }, new DatePicker { }, new Editor { Text = "Editor" }, new Entry { Placeholder = "Entry" }, new Image { Source = "crimson.jpg", HeightRequest = 44 }, new Label { Text = "Title View Label!" }, new Picker { ItemsSource = Enumerable.Range(0, 10).Select(i => $"Item {i}").ToList(), Title = "Picker" }, new ProgressBar { Progress = 50 }, new Slider { }, new Stepper { }, new Switch { }, new TimePicker { } }; int idx = 0; NavigationPage.SetTitleView(this, CreateTitleView(controls[idx])); rootNavPage.On <Android>().SetBarHeight(450); rootNavPage.On <iOS>().SetPrefersLargeTitles(false); Content = new ScrollView { Content = new StackLayout { Children = { new Button { Text = "Go to SearchBarTitlePage", Command = new Command(() => { rootNavPage.PushAsync(new SearchBarTitlePage(rootNavPage)); }) }, new Button { Text = "Change BarTextColor", Command = new Command(() => { if (toggleBarTextColor % 2 == 0) { rootNavPage.BarTextColor = Colors.Teal; } else { rootNavPage.BarTextColor = null; } toggleBarTextColor++; }) }, new Button { Text = "Change BarBackgroundColor", Command = new Command(() => { if (toggleBarBackgroundColor % 2 == 0) { rootNavPage.BarBackgroundColor = Colors.Navy; } else { rootNavPage.BarBackgroundColor = null; } toggleBarBackgroundColor++; }) }, new Button { Text = "Change Both to default", Command = new Command(() => { rootNavPage.BarTextColor = null; rootNavPage.BarBackgroundColor = null; }) }, new Button { Text = "Black background, white text", Command = new Command(() => { rootNavPage.BarTextColor = Colors.White; rootNavPage.BarBackgroundColor = Colors.Black; }) }, new Button { Text = "Toggle TitleIcon", Command = new Command(() => { var titleIcon = NavigationPage.GetTitleIconImageSource(this); if (titleIcon == null) { titleIcon = "coffee.png"; } else { titleIcon = null; } NavigationPage.SetTitleIconImageSource(this, titleIcon); }) }, new Button { Text = "Toggle TitleView", Command = new Command(() => { var titleView = NavigationPage.GetTitleView(this); if (titleView == null) { titleView = CreateTitleView(controls[idx]); } else { titleView = null; } NavigationPage.SetTitleView(this, titleView); }) }, new Button { Text = "Next TitleView", Command = new Command(() => { idx++; if (idx >= controls.Count) { idx = 0; } var titleView = CreateTitleView(controls[idx]); NavigationPage.SetTitleView(this, titleView); }) }, new Button { Text = "Toggle Back Title", Command = new Command(() => { var backTitle = NavigationPage.GetBackButtonTitle(rootNavPage); if (backTitle == null) { backTitle = "Go back home"; } else { backTitle = null; } NavigationPage.SetBackButtonTitle(rootNavPage, backTitle); }) }, new Button { Text = "Toggle Toolbar Item", Command = new Command(() => { if (ToolbarItems.Count > 0) { ToolbarItems.Clear(); } else { ToolbarItems.Add(new ToolbarItem { Text = "Save" }); } }) }, new Button { Text = "Toggle Title", Command = new Command(() => { if (Title == null) { Title = "NavigationBar Gallery - Legacy"; } else { Title = null; } }) }, new Button { Text = "Toggle BarHeight", Command = new Command(() => { if (rootNavPage.On <Android>().GetBarHeight() == -1) { rootNavPage.On <Android>().SetBarHeight(450); } else { rootNavPage.ClearValue(BarHeightProperty); } }) } } } }; }
void UpdateBackButtonTitle() { this.Control.BackButtonTitle = NavigationPage.GetBackButtonTitle(Element); }
protected virtual void UpdateToolbar() { ActionBarDrawerToggle toggle = _drawerToggle; if (Toolbar == null || NavigationStack.Count == 0 || CurrentPage == null || VirtualView == null) { return; } bool isNavigated = NavigationStack.Count > 1; Page currentPage = CurrentPage; _defaultNavigationIcon ??= Toolbar.NavigationIcon; if (isNavigated) { if (NavigationPage.GetHasBackButton(currentPage)) { Toolbar.NavigationIcon ??= _defaultNavigationIcon; if (toggle != null) { toggle.DrawerIndicatorEnabled = false; toggle.SyncState(); } var prevPage = (Page)NavigationStack[NavigationStack.Count - 2]; var backButtonTitle = NavigationPage.GetBackButtonTitle(prevPage); ImageSource image = NavigationPage.GetTitleIconImageSource(currentPage); if (!string.IsNullOrEmpty(backButtonTitle)) { Toolbar.NavigationContentDescription = backButtonTitle; } else if (image == null || Toolbar.SetNavigationContentDescription(image) == null) { Toolbar.SetNavigationContentDescription(Resource.String.nav_app_bar_navigate_up_description); } } else if (toggle != null && _flyoutPage != null) { toggle.DrawerIndicatorEnabled = _flyoutPage.ShouldShowToolbarButton(); toggle.SyncState(); } else { Toolbar.NavigationIcon = null; } } else { if (toggle != null && _flyoutPage != null) { toggle.DrawerIndicatorEnabled = _flyoutPage.ShouldShowToolbarButton(); toggle.SyncState(); Toolbar.SetNavigationContentDescription(Resource.String.nav_app_bar_open_drawer_description); } } Color tintColor = NavigationView.BarBackgroundColor; if (tintColor == null) { Toolbar.BackgroundTintMode = null; } else { Toolbar.BackgroundTintMode = PorterDuff.Mode.Src; Toolbar.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToNative()); } Brush barBackground = NavigationView.BarBackground; Toolbar.UpdateBackground(barBackground); Color textColor = NavigationView.BarTextColor; if (textColor != null) { Toolbar.SetTitleTextColor(textColor.ToNative().ToArgb()); } Color navIconColor = NavigationPage.GetIconColor(CurrentPage); if (navIconColor != null && Toolbar.NavigationIcon != null) { DrawableExtensions.SetColorFilter(Toolbar.NavigationIcon, navIconColor, FilterMode.SrcAtop); } Toolbar.Title = currentPage?.Title ?? string.Empty; if (Toolbar.NavigationIcon != null && textColor != null) { var icon = this.Toolbar.NavigationIcon as DrawerArrowDrawable; if (icon != null) { icon.Color = textColor.ToNative().ToArgb(); } } UpdateTitleIcon(); UpdateTitleView(); UpdateToolbarVisibility(); }