简体   繁体   English

C#Xamarin Forms ContentPage-顶部空白

[英]c# Xamarin Forms ContentPage - Gap on Top

This would seem to be really simple (and probably is), but I just can't seem to find any information about this. 这似乎很简单(也许是),但是我似乎找不到任何有关此的信息。

Take a look at: 看一眼: 在此处输入图片说明

There is a full width white gap on top. 顶部有一个全宽的白色缝隙。 What is it? 它是什么? How do I get rid of it or access it (add text, buttons, icons, etc)? 如何摆脱或访问它(添加文本,按钮,图标等)?

For this test, my code is super simple. 对于此测试,我的代码非常简单。 xaml: 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="TestApp.TestPage">
    <StackLayout VerticalOptions="FillAndExpand" Padding="0">
        <maps:Map x:Name="TestMap" IsShowingUser="true" MapType="Street" />
    </StackLayout>
</ContentPage>

.cs: .cs:

using Xamarin.Forms;

    namespace Test
    {
        public partial class TestPage : ContentPage
        {
            public TestPage()
            {
                InitializeComponent();
            }
        }
    }

app.xaml: app.xaml:

<ResourceDictionary>
    <Style TargetType="NavigationPage">
        <Setter Property="BarBackgroundColor" Value="White"/>
        <Setter Property="BarTextColor" Value="Black"/>
    </Style>
    <Style x:Key="DefaultPageStyle" TargetType="ContentPage">
        <Setter Property="BackgroundColor" Value="White"/>
    </Style>
</ResourceDictionary>

Edit: The comment from @Vulcan Lee, sent me on a path to finding the missing (key) information. 编辑:来自@Vulcan Lee的评论使我找到了丢失的(关键)信息。

Which was, inside App.xaml.cs, I had: 在App.xaml.cs中,我有:

public App()
{
    InitializeComponent();

    MainPage = new NavigationPage(new TestPage());
}

So, this has to do with the navigation menu. 因此,这与导航菜单有关。 How do I access, format or remove it? 如何访问,格式化或删除它?

The white space is actually navigation bar. 空格实际上是导航栏。

Change this: 更改此:

new NavigationPage(new TestPage())

to

new TestPage()

Or just remove the navigation bar if you still want to make the first page as a navigation page: 或者,如果您仍想将第一页作为导航页,则只需删除导航栏即可:

NavigationPage.SetHasNavigationBar(this, false);

I remember this change is introduced in Xamarin.Forms 2.3.x. 我记得Xamarin.Forms 2.3.x中引入了此更改。

You can try setting the map to VerticalOptions="FillAndExpand" . 您可以尝试将地图设置为VerticalOptions="FillAndExpand" It will not have much effect on the StackLayout because the StackLayout just wants to be what ever size it's children are. 它对StackLayout影响不大,因为StackLayout只是想成为StackLayout大小。 If setting the map's VerticalOptions does not work, you could instead set it's HeightRequest property manually. 如果设置地图的VerticalOptions无效,则可以手动设置其HeightRequest属性。

If all that fails, I would suggest putting the map into a Grid instead. 如果所有操作均失败,则建议将地图放Grid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM