Setting title in iOS NavBar in Xamarin Forms.

I have a NavigationPage that is moving between content pages. I set the title for the content page using its Title property, and on android it displays the title properly in the navigation bar. However, on iOS, it does not, but rather it will display that text as the back button text when I have pushed another page onto the navigation stack. How do I get iOS to show the proper title on the proper page?

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    If you assign this.Title to your contentpage?

  • That is what is strange, yes I did assign this.Title in the contentpage and it works just fine in android, but in iOS it does not show until I push a new page, and then it uses the this.Title of the previous contentpage as the back button text. Looking at the details, this is what iOS is expected to do in straight xamarin ios, but not in forms.

    At the very least I want to get it to see the this.Title on the root contentpage, because right now the layout looks really odd with no titling or the like. I know I must be missing something, or perhaps is there a xamarin.forms issue, but I can't imagine this would not have been brought up before.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I have this code

            Title = "Attività";
            Library.SetBackButton (this);
            NavigationPage.SetBackButtonTitle (this, "Attività");
    

    Where

    public static void SetBackButton(Page page, string iconName = "", bool hasBackButton = false) {
            if(Device.OS == TargetPlatform.Android)
                NavigationPage.SetTitleIcon (page, iconName);
            NavigationPage.SetHasNavigationBar (page, true);
            NavigationPage.SetHasBackButton (page, hasBackButton);
        }
    
Sign In or Register to comment.