【问题标题】:Xamarin Forms Secondary ToolbarItem in TabbedPage on iOSXamarin 在 iOS 上的 TabbedPage 中形成辅助 ToolbarItem
【发布时间】:2017-08-29 14:15:25
【问题描述】:

我的应用程序在 iOS 上的行为很奇怪,我有一个带有 3 个选项卡的 TabPage。 在第一张图片上,您可以看到我在第一个选项卡上有 4 个辅助工具栏项。奇怪的是在没有辅助工具栏项的地图页面上,导航栏和地图之间的空间仍然存在。 有谁知道如何解决这个问题,或者这是否是 Xamarin 的错误?

NavPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:view="clr-namespace:CarPar.View;assembly=CarPar"
            x:Class="CarPar.Navigation.NavPage"
            Title = "{Binding PageTitle}">

  <view:HomePage />
  <view:MapPage />
  <view:FavoritePage />

</TabbedPage>

HomePage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:view="clr-namespace:CarPar.View;assembly=CarPar"
             x:Class="CarPar.View.HomePage"
             Title="City"
             Icon="home.png">
    <ContentPage.ToolbarItems>
        <ToolbarItem Text="Alphabetisch" />
        <ToolbarItem Text="Freie Plätze" />
        <ToolbarItem Text="Prozent frei" />
        <ToolbarItem Text="Entfernung" />
    </ContentPage.ToolbarItems>
    <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
        <SearchBar Placeholder="Parkhaus suchen" Text="{Binding SearchText}" />
    ...
    <StackLayout>
</ContentPage>

MapPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
             x:Class="CarPar.View.MapPage"
             Title="Karte"
             Icon="map.png">
    <ContentPage.Content>
        <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
            <maps:Map x:Name="ParkingMap"
          IsShowingUser="True"
          MapType="Street"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

【问题讨论】:

  • 看起来很明显;工具栏项目是您的HomePage.xaml 的一部分,通过按地图选项卡,您可以有效地切换到没有工具栏项目的MapPage.xaml
  • @GeraldVersluis 这就是重点。没有工具栏项,但标题和地图之间的空间仍然存在,这就是问题所在。
  • 该应用在 Android 中的功能是否相同?或者它实际上是 iOS 特定的东西?
  • @EnriqueZavaleta 不,它只在 iOS 中。在 Android 中,辅助工具栏不在标题下方,因此空间没有问题。
  • 您是如何准确地创建辅助工具栏的?是用自定义渲染器完成的吗?如果是这样,您能否将渲染器代码添加到您的问题中?

标签: xaml xamarin xamarin.forms toolbar tabbedpage


【解决方案1】:

您在推送到标签栏堆栈的第一个“视图控制器”中创建工具栏项。这些被实例化为导航控制器的一部分。因此,当您加载没有任何信息传递给工具栏的第二个页面时,它不会显示,但在技术上仍然是视图的一部分,因此它呈现顶部的空间,我相信有一些阻止这种行为的方法,第一个使用 AutoLayout 中继。

    public MySecondPage()
    {
        InitializeComponent();
        NavigationPage.SetHasNavigationBar(this, false);  // Hide nav bar
    }

如果这不起作用,请告诉我,还有其他不太整洁的选项。

【讨论】:

    猜你喜欢
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    • 2021-03-21
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多