我有一个简单的(文件->新项目)XF应用程序,不会显示NavigationPage.TitleView
iOS的内容。Android运行正常。我究竟做错了什么?
源代码可以在这里找到。
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>
如Jason
评论中所述,NavigationPage.TitleView是Navigation Bar
in中的一部分NavigationPage
。要自定义TitleView
,您首先应创建NavigationPage
:
public App ()
{
MainPage = new NavigationPage (new Page1());
}
然后TitleView
在ContentPage中设置:
<NavigationPage.TitleView>
<Label Text="Page Title" />
</NavigationPage.TitleView>
请参阅:分层导航
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句