【问题标题】:Xamarin.Forms TabbedPageXamarin.Forms 标签页
【发布时间】:2019-01-01 23:25:40
【问题描述】:

我在这个项目中有一个小问题。这是我的标签页声明:

<?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:local="clr-namespace:JacksCurrencyConverter;assembly=JacksCurrencyConverter"
            x:Class="JacksCurrencyConverter.StartPage"
            x:Name="Children"
            HeightRequest="10" 
            WidthRequest="10">

    <TabbedPage.Children>
        <local:MainPage Icon="currency.png"  Title="Exchange"/>
        <local:FavouritesPage Icon="favourites2.png"  Title="Favourites"/>
        <local:MainPage Icon="statistics2.png" Title="Info"/>
    </TabbedPage.Children>
</TabbedPage>

那么这就是它在 iOS 和 Android 中的样子:

iOS:

安卓:

如何减少 Android 上 tabbpage 中显示的空白蓝色空间?

要减少的蓝色空间:

抱歉,我需要至少 10 个声望才能发布图片。

【问题讨论】:

  • 你能告诉我你在哪里调用这个页面的构造函数的代码吗?
  • @G.hakim public App() { InitializeComponent(); MainPage = new NavigationPage(new StartPage()); }

标签: c# xamarin.forms xamarin.ios xamarin.android tabbedpage


【解决方案1】:

你得到这个空间的原因是因为你有一个导航页面包裹在你的正常内容页面上

这样做会删除你的空间:

Mainpage= new StartPage();

【讨论】:

    【解决方案2】:

    添加水平和垂直选项,这应该可以修复顶部的空白空间。

     <TabbedPage>
         <ContentPage Title="Exchange" 
                      HorizontalOptions="StartAndExpand" 
                      VerticalOptions="Center" Padding="0">
             <local:MainPage Icon="currency.png"  Title="Exchange"/>
         </ContentPage>
         <ContentPage Title="Favourites" 
                      HorizontalOptions="StartAndExpand" 
                      VerticalOptions="Center" Padding="0">
              <local:FavouritesPage Icon="favourites2.png"  Title="Favourites"/>
         </ContentPage>
         <ContentPage Title="Info" 
                      HorizontalOptions="StartAndExpand" 
                      VerticalOptions="Center" Padding="0">
             <local:MainPage Icon="statistics2.png" Title="Info"/>
         </ContentPage>
    </TabbedPage>
    

    【讨论】:

    • 这会引发以下错误:没有为“Horizo​​ntalOptions”找到属性、可绑定属性或事件,或者值和属性之间的类型不匹配。 (JacksCurrencyConverter)
    • 你能试试在 中添加水平和垂直选项吗
    【解决方案3】:

    您可以将NavigationPage.HasNavigationBar="False" 添加到 XAML 中的 TabbedPage 标记。

    那么你的代码应该是这样的:

    <TabbedPage
     xmlns="http://xamarin.com/schemas/2014/forms"
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
     xmlns:local="clr-namespace:JacksCurrencyConverter;assembly=JacksCurrencyConverter"
     x:Class="JacksCurrencyConverter.StartPage"
     x:Name="Children"
     HeightRequest="10" WidthRequest="10"
     NavigationPage.HasNavigationBar="False">
    ...
    

    另一种方法是在页面的构造函数或 OnAppearing 函数中调用 NavigationPage.SetHasNavigationBar(this, false);

    【讨论】:

      猜你喜欢
      • 2019-05-13
      • 2015-09-24
      • 1970-01-01
      • 1970-01-01
      • 2020-11-01
      • 2017-04-13
      • 2019-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多