【问题标题】:Xamarin forms Center NavigationPage titleXamarin 表单中心 NavigationPage 标题
【发布时间】:2021-01-16 03:10:42
【问题描述】:

我有问题。我使用了 Navigation.PushAsync(),所以现在在我的第二页上,我在 NavigationBar 中有一个后退箭头。现在我也想在 NavigationBar 的中间添加一个 titleview,但它并没有完全居中,而是更靠右,因为有后退按钮。

我已经尝试将它设置为这样的 AbsoluteLayout:

<NavigationPage.TitleView>
    <AbsoluteLayout>
        <Label Text="MyTitle" FontSize="20" AbsoluteLayout.LayoutBounds="0.5, 0.5" AbsoluteLayout.LayoutFlags="PositionProportional" />
    </AbsoluteLayout>
</NavigationPage.TitleView>

但还是一样的结果:(

我该如何解决这个问题?

【问题讨论】:

    标签: xaml xamarin xamarin.forms xamarin.android xamarin.ios


    【解决方案1】:

    移除后退按钮

    <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"
                 NavigationPage.HasBackButton="False">
    

    添加自定义图片并使用 TapGesture(或者你可以使用 FontAwesome 之类的)

    <AbsoluteLayout>
                <Image AbsoluteLayout.LayoutBounds="0, 0.5" AbsoluteLayout.LayoutFlags="PositionProportional" WidthRequest="20" HeightRequest="20"
                       Source="arrow16">
                    <Image.GestureRecognizers>
                        <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
                    </Image.GestureRecognizers>
                </Image>
                <Label Text="MyTitle" FontSize="20" AbsoluteLayout.LayoutBounds="0.5, 0.5" AbsoluteLayout.LayoutFlags="PositionProportional" />
    </AbsoluteLayout>
    

    点击事件弹出页面

    private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
    {
       await Navigation.PopAsync();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-17
      • 1970-01-01
      • 2020-10-09
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      • 1970-01-01
      相关资源
      最近更新 更多