Change the text on the Back Button

RyanWatsonRyanWatson USMember ✭✭✭

After navigating to a new page a Back button is generated. Is there a way to change the text that is on the button?

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Set the Title property of the page you are going back to.

  • RyanWatsonRyanWatson USMember ✭✭✭

    Set it before going back to the page? I did it on OnAppearing and it would show a flash of text that changes.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Set it in the constructor.

  • DirkWeltzDirkWeltz DEMember ✭✭✭

    @adamkemp‌: what is with the static method NavigationPage.SetBackButtonTitle(Page, string). I tried it, but it don't work. Also NavigationPage.SetHideBackButton(Page, bool). I like to have a back function, that work without animation.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I don't understand what you're trying to do. The first method sets the title of the back button for the given page. I believe the default would be the Title of the page itself. The second sets whether the given page has a back button. There is a weird comment in the documentation about animation, but I think that's a mistake. These APIs have nothing to do with animation.

  • DirkWeltzDirkWeltz DEMember ✭✭✭

    First of all I want to set the back button title to string.Empty. That don't work. They show "Back" or the title of the page before. Next I want to hide on some pages the back button. That works, but I could show the back button later on the same page (back button should be hidden only in some cases for a page). That don't work.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I don't know how to do that.

  • RyanWatsonRyanWatson USMember ✭✭✭

    I'm missing something... You said to set it in the Constructor... there isn't a BackButton property or SetBackButton() method for a ContentPage.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I said to set the Title of the page in its own constructor. That is normally how you change the text of the back button (for when that page is the one you are going back to). I was answering a simpler question, though. The original question didn't require changing it multiple times or hiding the button dynamically.

  • RyanWatsonRyanWatson USMember ✭✭✭

    My scenario:
    Three pages with titles of "Page 1", "Page 2", "Page 3". I want the back button on Page 2 and Page 3 to say "Back" instead of "Page 1" and "Page 2" but yet the Titles of the pages stay what I actually named them.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Like I said, I don't know how to do that. If SetBackButtonTitle doesn't work for you then you may need a custom renderer. I'm only guessing, though.

  • DirkWeltzDirkWeltz DEMember ✭✭✭

    Sorry for the late answer (had to sleep a little bit :) ) and the confusion.

    This morning I checked it again and that is, what I found:

    • NavigationPage.SetBackButtonTitle(Page, string)works perfect. It is a static function and I assume, that it is having a list in the background, which page has which back button title. But you have to remember, that it handles the title of the back button, which is shown on other pages to go back to the given page. I set it in the wrong place. That was my fault. I thought, I could set the title of the back button, which is shown on the given page.

    @RyanWatson: In your case, you set the back button title, which leads back to Page1, in the constructor of Page1. Set the title to nulland you get the default text ("Back" in english versions). This text is than shown on the back button of Page2. Do the same for Page2 in this constructor.

    • You could set, if the back button is shown by NavigationPage.SetHideBackButton(Page, bool).

    @JasonSmith‌: Sorry, Jason, don't know, who else could handle this :). It isn't correct, that you could add animation with this function. It isn't correct in the online help and it isn't correct on the website.

    • The new NavigationPage.HasBackButton is only a bindable property for NavigationPage.Get/SetHasBackButton().

    What I don't get up to now is a dynamic back button. Perhaps I had to do this with a custom renderer and an own bar item :).

Sign In or Register to comment.