【问题标题】:Xamarin Forms - NavigationPage.TitleView doesn't work on iOSXamarin 表单 - NavigationPage.TitleView 在 iOS 上不起作用
【发布时间】:2019-10-18 10:08:00
【问题描述】:

我有一个简单的(文件->新项目)XF 应用程序,它不会显示 iOS 的 NavigationPage.TitleView 内容。安卓运行良好。我做错了什么?

源码可以在here找到。

XAML

<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"
             mc:Ignorable="d"
             x:Class="SampleApp.MainPage">

    <NavigationPage.TitleView>
        <Grid BackgroundColor="Blue">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0"
                   TextColor="Black"
                   Text="Page Title" />
        </Grid>
    </NavigationPage.TitleView>

    <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" 
               HorizontalOptions="Center"
               VerticalOptions="CenterAndExpand" />
    </StackLayout>

</ContentPage>

这是输出...

我也试过 StackLayout,结果一样...

<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"
             mc:Ignorable="d"
             x:Class="SampleApp.MainPage">

    <NavigationPage.TitleView>
        <StackLayout BackgroundColor="Blue" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <Label Grid.Row="0" Grid.Column="0"
                   TextColor="Black"
                   Text="Page Title" />
        </StackLayout>
    </NavigationPage.TitleView>

    <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" 
               HorizontalOptions="Center"
               VerticalOptions="CenterAndExpand" />
    </StackLayout>

</ContentPage>

【问题讨论】:

  • 您的 ContentPage 是否包含在 NavigationPage 中?

标签: xamarin xamarin.forms xamarin.ios


【解决方案1】:

正如评论中提到的JasonNavigationPage.TitleViewNavigation BarNavigationPage 中的一部分。要自定义TitleView,您应该首先创建一个NavigationPage

public App ()
{
  MainPage = new NavigationPage (new Page1());
}

然后在 ContentPage 中设置TitleView

<NavigationPage.TitleView>
    <Label Text="Page Title" />
</NavigationPage.TitleView>

参考:Hierarchical Navigation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 2018-11-11
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多