我有一个简单的(文件->新项目)XF应用,该应用不会显示iOS的NavigationPage.TitleView
内容。 Android运行正常。我在做什么错了?
可以找到源代码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>
答案 0 :(得分:1)
如评论中的Jason
所述,
NavigationPage.TitleView是Navigation Bar
中NavigationPage
的一部分。要自定义TitleView
,您首先应创建一个NavigationPage
:
public App ()
{
MainPage = new NavigationPage (new Page1());
}
然后在ContentPage中设置TitleView
:
<NavigationPage.TitleView>
<Label Text="Page Title" />
</NavigationPage.TitleView>