Xamarin.Forms UWP项目标题栏和制表符之间的空白空间
我实际上是新的Xamarin.Forms,我正在开发一个相当简单的跨平台应用程序。该应用程序在Android中显示效果不错,但在UWP中存在一个愚蠢的空白区域。该项目包含一个带有4个NavigationPages的TabbedPage,以便在其中推送和弹出页面。Xamarin.Forms UWP项目标题栏和制表符之间的空白空间
稍微深入UWP平台细节后,我能够改变我的标签的风格。我一直在寻找3天的解决方案,这让我疯狂。到目前为止,我发现的唯一解决方案(借助VS 2015的Live Visual Tree)将从CommandBar(如第三张附图所示)将可见性属性更改为“折叠”。但这不是一个解决方案,因为它只会在运行时消失。
任何人都可以帮忙吗? 在此先感谢。
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
。所有行为和用户界面在所有平台上都保持不变。
现在你在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
区域。
非常感谢你的回答和你的时间。我希望避免自定义渲染器,但现在我可以看到它是非常必要的。我会让你知道你的建议。 – kkaragki
我所做的一切正是因为你告诉我,但在_this_行: 'Control.TitleVisibility = Windows.UI.Xaml.Visibility.Collapsed;' 的VS2015显示我的错误消息: _Error CS1061 \t“FormsPivot”呢不包含“TitleVisibility”的定义,并且没有可以找到接受“FormsPivot”类型的第一个参数的扩展方法“TitleVisibility”(您是否缺少使用指令或程序集引用?)_ 对不起再次打扰您 – kkaragki
是你可能没有从NuGet安装的最新版本的Xamarin.Forms?我检查了Xamarin.Forms GitHub和属性应该在那里,所以它是相当混乱:-) - https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.WinRT .Phone/FormsPivot.cs –
您可以发布您正在使用的页面的Xamarin.Forms XAML布局吗? –