DEV Community

Enmanuel Toribio
Enmanuel Toribio

Posted on • Originally published at on

Changing that Back button label on iOS with Xamarin Forms

Some context

I’ve been working on the app for CodecampSDQ (iOS | Android) to be celebrated on the premises of Intec this June 1st. The code is based on this repo and we have made some adequations that I will probably talk about in greater detail later.

I found myself at an impasse for a few minutes doing the localization for the app when trying to change the Back button label on iOS and that’s what I’m going to talk about next.

The meat and potatoes

To change the label content all you have to do is set this property NavigationPage.BackButtonTitle. You can set it up using XAML or C#

Here is the thing though, you need to set the property from within the ContentPage you’re navigating from, instead of the destination page. In other words, say you have Page1 and Page2 and you want Page2’s back button label to say “Take me home”, you would need to set the NavigationPage.BackButtonTitle property on Page1 for it to work. If you set it on Page2 it will simply not work and you will get the Back button.

Some explaining ensues

To some of you getting started, this implementation may seem a little backward at first. You will probably think “Why would I change the presentation of a page from another page?” and that’s what happened through my mind after spending an unhealthy amount of time trying to figure out why the back labels wouldn’t change.

A good Justification may be the following: Let’s imagine you want to be able to navigate to a page from different paths (we will call these potential paths source pages ) and you are reusing a page to show samely structured data in different contexts (we will call that a detail page ). In this scenario, you want to be able to remind the user where they are going to land after pressing that back button from the detail page. With the current implementation, you can add as many source pages as you need and you don’t have to modify the Details page at all for every one of them nor will you need to pass a parameter or something in the ViewModel just to specify this value.

In conclusion

Overall I think this is a fun simple feature that can make your life easier and help us achieve world peace but remember to implement it correctly.

If you liked the article and would like to read more articles like this I encourage you to check the other content on the site and if you really really like it I hope you share it with your pal’s and gal’s print it and paste it at your town square or just share it on social media, that works too. Thanks for passing by and have a good one.

The post Changing that Back button label on iOS with Xamarin Forms appeared first on Enmanuel Toribio.

Top comments (0)