Xamarin Forms - NavigationPage.TitleView не работает на iOS - PullRequest
0 голосов
/ 17 октября 2019

У меня есть простое (File-> New Project) приложение XF, которое не отображает контент NavigationPage.TitleView для iOS. Андроид работает нормально. Что я делаю не так?

Исходный код можно найти здесь .

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>

Вотвывод ...

enter image description here

Я также попробовал 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>

1 Ответ

1 голос
/ 18 октября 2019

Как указано в комментарии Jason, NavigationPage.TitleView является частью Navigation Bar в NavigationPage. Чтобы настроить TitleView, сначала необходимо создать NavigationPage:

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

Затем установить TitleView в ContentPage:

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

См .: ИерархическаяНавигация

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...