How to change the Back Button Text on Xamarin.Forms

15,662

Solution 1

You have to set the Backbutton title of your previous page as string.Empty. By default it's the title of the previous page on the navigation stack that is shown as the back button text.

Also Android does not support this property.

Solution 2

Due to the topic:

One of the things that is a little bit unintuitive about this API is that you are setting the title for the back button that shows up when this page is the one that you are going back to. For example, you are trying to set the title to "Home". That means you should be calling this method on the Page that represents the "home" page, not the page that is visible when the back button that says "Home" is showing.

So, if you are navigating from Page1 to Page2, you should set NavigationPage.SetBackButtonTitle(this, "") in constructor of Page1 and on Page2 you will see the empty title of back button.

Solution 3

You can also do it from the Code Behind of the current xaml page

public TodoPage()
{
    InitializeComponent();
    NavigationPage.SetBackButtonTitle(this, "Back");
}

NB: It has to be done on the previous page you want to set.

e.g. Page A has to have the code if you want Page B to show "Back" title.

Solution 4

Belated answer but maybe someone will find this useful in the future… Anyhow, if you wish to get rid of the back button title from XAML, you can either add NavigationPage.BackButtonTitle="" for any ContentPage that should have the title removed or you can define new ContentPage style in your App.xaml file like this:

<Style x:Key="ContentPageStyle" TargetType="ContentPage">
    <Setter Property="BackgroundColor" Value="White" /><!-- just an example of other things that can be in here -->
    <Setter Property="NavigationPage.BackButtonTitle" Value="" />
</Style>

I was, however, unable to turn this into an implicit global style that would get applied automatically without the need to specify Style="{StaticResource ContentPageStyle}" for each ContentPage – I'm not sure why that one doesn't work.

Solution 5

You can set the attribute NavigationPage.BackButtonTitle on ContentPage

For example:

<?xml version="1.0" encoding="utf-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:T3R" mc:Ignorable="d" Title="Title of Page" NavigationPage.BackButtonTitle="Cancel" x:Class="T3R.MainPage">

Remember the following:

  • I understand this only works on iOS
  • For any given page, the back button title is set by the page that presents it. This way, the button label can vary with respect to the page that precedes it on the navigation stack (of which there can be many).
Share:
15,662
acido
Author by

acido

Software Developer and Database Architect, Design Lover, Life Enjoyer

Updated on June 18, 2022

Comments

  • acido
    acido about 2 years

    I have been trying to change the text of the back button in Xamarin.Forms without luck.

    I tried already this code with no luck:

    NavigationPage.SetBackButtonTitle(this, "");
    

    I'm using a MasterDetailPage.

    I tried to add the code into the constructor of the XAML cs file.

    Libraries used: PRISM 6.2.0, Xamarin Forms 2.3.1.114

    Any suggestion or idea?

    Thanks in advance

  • acido
    acido almost 8 years
    Thanks @Rohit this worked very good. Just curiosity in Android how can we hide the back button instead since all android phones already provide a hard and/or soft back button?
  • Rohit Vipin Mathews
    Rohit Vipin Mathews almost 8 years
    For Android you have to create a custom render and set the properties of actionbar. forums.xamarin.com/discussion/24517/… or forums.xamarin.com/discussion/23794/…
  • John
    John about 6 years
    Use ApplyToDerivedTypes="true" in the style to make the pages that inherit from ContentPage get styled as well.
  • Dave Friedel
    Dave Friedel about 6 years
    It should also be noted, if you're using TabbedPages - you should place it in the TabbedPage constructor not the ContentPage of the children.
  • LeRoy
    LeRoy almost 6 years
    @knocte make sure your setting it on the previous page and not on the page you want it to appear
  • Washington Morais
    Washington Morais over 3 years
    NavigationPage.BackButtonTitle="" Dude, You are AWESOME!!!!