3

我实际上是Xamarin.Forms的新手,我正在开发一个相当简单的跨平台应用程序。该应用程序在 Android 中显示得足够好,但在 UWP 中有一个愚蠢的空白区域。该项目由一个 TabbedPage 组成,其中包含 4 个 NavigationPages,以便在其中推送和弹出页面。

在深入了解 UWP 平台细节后,我能够更改选项卡的样式。我一直在寻找 3 天的解决方案,这让我发疯。到目前为止,我找到的唯一解决方案(在 VS 2015 的 Live Visual Tree 的帮助下)是从 CommandBar 将Visibility属性更改为“Collapsed”(如第三张附图所示)。但这不是解决方案,因为它只会在运行时消失。

任何人都可以帮忙吗?提前致谢。

Android 视图, UWP 视图,实时可视化树

编辑: 我的MainPage.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:local="clr-namespace:_TIF_Xamarin;assembly=_TIF_Xamarin"
            x:Class="_TIF_Xamarin.MainPage">

  <!--4 different tabs, which also are Navigation Pages-->
  <NavigationPage Title="Home">
    <x:Arguments>
      <local:HomePage />
    </x:Arguments>
  </NavigationPage>

  <NavigationPage Title="Exhibitor">
    <x:Arguments>
      <local:ExhibitorsPage />
    </x:Arguments>
  </NavigationPage>

  <NavigationPage Title="Exhibits">
    <x:Arguments>
      <local:ExhibitsPage />
    </x:Arguments>
  </NavigationPage>

  <NavigationPage Title="More">
    <x:Arguments>
      <local:MorePage />
    </x:Arguments>
  </NavigationPage>

</TabbedPage> 
4

1 回答 1

1

您需要为其创建一个自定义TabbedPage渲染器,然后是一个 UWP 渲染器。

CustomTabbedPage首先在 PCL 中创建一个:

public class CustomTabbedPage : TabbedPage { }

在您的 XAML 中,使用 thisCustomTabbedPage而不是TabbedPage. 所有行为和 UI 在所有平台上都将保持不变。

现在您在 UWP 项目中创建一个渲染器:

[assembly: ExportRenderer(typeof(CustomTabbedPage), typeof(CustomTabbedPageRenderer))]

namespace App.UWP
{

    public class CustomTabbedPageRenderer : TabbedPageRenderer
    {
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
            Control.TitleVisibility = Windows.UI.Xaml.Visibility.Collapsed;
        }
    }
}

我们使用FormsPivot.TitleVisibility来隐藏该Title区域。

于 2016-11-26T11:14:04.260 回答