Setting BackButtonTitle with Prism ?

boris_dvboris_dv USMember ✭✭

Hi,

i have a Xamarin.Forms app using Prism. The main page is a MasterdetailPage with few buttons that navigate to other pages ... (still hamburger menu on the navigation bar) but when i navigate from those pages (now i have a classic navigation bar instead of hamburger) .. lets say to some item detail page i want to have a custom text next to the backbutton arrow.

I tried setting NavigationPage.BackButtonTitle in xaml of the MainPage but it doesnt work ..
If i try to set HasBackButton="False" .. the back button is replaced by Hamburger(?).

How can i change the backbuttontitle from viewmodel ?
Or how can i hide the burger menu ? and use TitleView ...

Also i noticed if i change the BackButtonTitle in the MasterDetail detailpage it changes the backbutton title on the ItemDetailPage too ...

Thanks for any advice

Answers

  • NMackayNMackay GBInsider, University mod

    @boris_dv said:
    Hi,

    i have a Xamarin.Forms app using Prism. The main page is a MasterdetailPage with few buttons that navigate to other pages ... (still hamburger menu on the navigation bar) but when i navigate from those pages (now i have a classic navigation bar instead of hamburger) .. lets say to some item detail page i want to have a custom text next to the backbutton arrow.

    I tried setting NavigationPage.BackButtonTitle in xaml of the MainPage but it doesnt work ..
    If i try to set HasBackButton="False" .. the back button is replaced by Hamburger(?).

    How can i change the backbuttontitle from viewmodel ?
    Or how can i hide the burger menu ? and use TitleView ...

    Also i noticed if i change the BackButtonTitle in the MasterDetail detailpage it changes the backbutton title on the ItemDetailPage too ...

    Thanks for any advice

    This isn't a Prism issue. Prism does not affect the behavior of Forms as such, it is an application framework that provides MVVM support.

    https://stackoverflow.com/questions/39027111/how-to-change-the-back-button-text-on-xamarin-forms

    You will need to use custom renderers to modify the default Forms behavior or use TitleView.

    See the titleview documentation

    https://docs.microsoft.com/en-gb/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical#displaying-views-in-the-navigation-bar

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

    Be aware that there is this issue for TitleView which in my opinion makes it unusable unless your background colours mask the lack of horizontal fill.

    An alternative is to set

    NavigationPage.SetHasNavigationBar(this, false);

    in the code behind for your pages, and create your own navigation header control.

    I have to admit I'm not sure if this works with Master/Detail pages - I have avoided master/detail!

Sign In or Register to comment.