Changing that Back button label on iOS with Xamarin Forms

Screen Shot 2019-05-29 at 10.49.08 AM
Share on facebook
Share on twitter
Share on linkedin

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.

Did you like the post and would like to leave a reply? You can mention me on twitter @eatskolnikov so we can have a conversation about it

Share it with your friends

Share on facebook
Share on twitter
Share on linkedin

Want to get these post in your inbox?

Type your email down here and you will get a weekly digest of the post here

Other articles on the site

app center

Crashing like a pro with App Center

Accept your fate Face it, your app is going to crash at some point. No matter how well you test it or how great the QA team is nor the 100% code coverage or how extensive the device suite for testing you have. There are always going to be edge

Read More »
looks

Prettying things up with Styles

Using styles you can define a consistent UI for your app and is a great way to make your XAML files more readable and maintainable in the long term. Some neat characteristics of styles: They are very easy to define. Can be inherited to minimize code reuse. Can be defined

Read More »