【发布时间】:2019-04-24 12:24:10
【问题描述】:
我在MainPage 中添加了TitleView 以显示在Navigationbar 上,但当我导航到其他页面Navigationbar 显示为空时,它仅显示MainPage。
下面的代码我在 MainPage.xaml 文件中
<NavigationPage.TitleView>
<RelativeLayout HorizontalOptions="Fill"
<Image Source="bell.png" HeightRequest="25" WidthRequest="25" x:Name="imgBell"
RelativeLayout.YConstraint="{ConstraintExpression
Type=RelativeToParent,
Property=Height,
Factor=0.018,Constant=10}">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding GetStaffAnnouncementCommand}"></TapGestureRecognizer>
</Image.GestureRecognizers>
</Image>
<Label FontSize="10" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" BackgroundColor="Transparent" Text="2" TextColor="Red"
HeightRequest="22" WidthRequest="23" x:Name="labelText">
</Frame>
</RelativeLayout>
</NavigationPage.TitleView>
当我点击 铃铛图标 并移动到第二页时 TitleView 根本不显示
如何显示所有页面的通用TitleView?
【问题讨论】:
-
您是否也将整个标题视图代码放在第二页中?
-
为了减少这项工作,您可以创建一个标题视图的通用控件并在所有其他页面中使用它,但是您必须使用
在要显示标题视图的每个页面中。 -
是的,这可以做到,但我只是想避免在所有页面中都有 TitleView。
-
您还可以创建带有标题视图的通用 ContentPage,并在需要时仅使用该通用页面,就像您在 xaml 中声明页面一样。
标签: xamarin xamarin.forms navigationbar titleview