【问题标题】:Navigation bar not displaying page title in Xamarin Forms导航栏未在 Xamarin Forms 中显示页面标题
【发布时间】:2019-11-19 05:39:57
【问题描述】:

我无法进行简单的测试以在我的 Xamarin 表单应用程序的导航栏中显示标题。我在下面提供我的代码,基本上当我在内容页面上设置标题并将内容页面包装在导航页面中时,导航栏不会显示内容页面中的相应标题。

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>

但我在导航栏中什么也看不到

有没有人见过这种行为或有什么建议?谢谢!

【问题讨论】:

  • 你在真机上测试过吗?
  • 不,我没有,只是在模拟器上。明天我将尝试开发设备。你认为这是一个模拟器的问题?它似乎可以加载其他所有内容。
  • 我的猜测是,如果有意义的话,标题的 NavigationBar 颜色和 TextColor 是相同的尝试使用 BarTextColor 更改它,看看是否适合您
  • @Schwagmister 如果我可以将其添加为答案并且您可以标记它,那就太好了:D
  • 它说我必须等待 2 天才能标记我自己的答案 D:

标签: xamarin xamarin.forms xamarin.android


【解决方案1】:

根据 FreakyAli 的回复,我测试了设置导航栏文本颜色,现在我可以看到标题了。感谢 FreakyAli 的建议!

作为参考,我在我的 App.cs 中添加了以下内容

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

Current.MainPage = nav;

【讨论】:

    猜你喜欢
    • 2021-07-16
    • 1970-01-01
    • 2019-10-06
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-02
    • 1970-01-01
    相关资源
    最近更新 更多