gpt4 book ai didi

c# - Xamarin.Forms UWP 项目中标题栏和选项卡之间的空白令人恼火

转载 作者:行者123 更新时间:2023-11-30 17:35:35 24 4
gpt4 key购买 nike

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

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

有人可以帮忙吗?提前致谢。

Android View , UWP View , Live Visual Tree

编辑:我的 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>

最佳答案

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

首先在 PCL 中创建一个 CustomTabbedPage:

public class CustomTabbedPage : TabbedPage { }

在您的 XAML 中,使用此 CustomTabbedPage 而不是 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 区域。

关于c# - Xamarin.Forms UWP 项目中标题栏和选项卡之间的空白令人恼火,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40816708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com