0
votes

I have been unable to get a simple test working to display a title in the Navigation bar of my Xamarin forms app. I am providing my code below, basically when I set the title on the content page and wrap the content page in a navigation page, the navigation bar is not displaying the corresponding title from the content page.

App.cs

public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
            Current.MainPage = new NavigationPage(new Presentation.Views.SettingsDeviceUnitView());
        }
    }

ContentPage.cs

[XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class SettingsDeviceUnitView : ContentPage
    {
        public SettingsDeviceUnitView()
        {
            InitializeComponent();
        }
    }

ContentPage.xaml

<?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:Controls="clr-namespace:GFIApp.Presentation.Controls"
             mc:Ignorable="d"
             x:Class="TestApp.Presentation.Views.SettingsDeviceUnitView"
             BackgroundColor="{StaticResource Key=ColorPrimary}"
             Title="TestTitle">
    <ContentPage.Content>
        <Grid>
        </Grid>
    </ContentPage.Content>
</ContentPage>

Yet I see nothing in the navigation bar

No title in navigation bar

Has anyone seen this behavior before or have any suggestions? Thank you!

1
Did you test it on a real device?Anand
No I have not, just on an emulator. I will try a Dev device tomorrow. Do you think it's an emulator issue? It seems to load everything else fine.Schwagmister
My guess is that the NavigationBar colour and the TextColor of your Title is the same if that makes sense Try using BarTextColor to change that and see if that works out for youFreakyAli
@Schwagmister It would be great if I could add this as the answer and you could mark that :DFreakyAli
It says I have to wait 2 days to mark my own answer D:Schwagmister

1 Answers

0
votes

Per FreakyAli's response I tested setting the navigation bar text color and I am now able to see the title. Thank you for the suggestion FreakyAli!

For reference, I added the following in my App.cs

NavigationPage nav = new NavigationPage(new Presentation.Views.SettingsDeviceUnitView());
nav.BarTextColor = Color.White;

Current.MainPage = nav;