此Xamarin Forms ContentPage中的空白行从何而来?

时间:2019-05-13 22:56:21

标签: xamarin xamarin.forms

下面的图像来自Xamarin Forms应用程序。注意绿色和红色区域之间的白色区域。我想弄清楚这个白色区域是哪里来的?我认为绿色和红色会紧挨着。

enter image description here

这是产生以上内容的代码。我正在使用ControlTemplate,这是我设计的要求(我正在使用BoxView来说明此问题的问题)...

基本类-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"
             x:Class="WP.MobileMidstream.Device.Pages.DialogBase"
             Visual="Material"             
             >
    <ContentPage.ControlTemplate>
        <ControlTemplate>
            <StackLayout>
                <BoxView BackgroundColor="Green" />
                <ContentPresenter VerticalOptions="FillAndExpand"
                                  BackgroundColor="Red" />
            </StackLayout>
        </ControlTemplate>
    </ContentPage.ControlTemplate>
</ContentPage>

基类-后面的代码-注意导航栏未显示

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class DialogBase : ContentPage
{
    public DialogBase()
    {
        InitializeComponent();

        NavigationPage.SetHasNavigationBar(this, false);
    }
}

正在显示扩展DialogBase的页面

<?xml version="1.0" encoding="utf-8" ?>
<d:DialogBase xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="clr-namespace:WP.MobileMidstream.Device.Pages"
             x:Class="WP.MobileMidstream.Device.Pages.AdjustmentEditPage">
    <ContentPage.Content>
        <StackLayout>
            <Label Text="Welcome to Xamarin.Forms!"
                VerticalOptions="CenterAndExpand" 
                HorizontalOptions="CenterAndExpand" />
        </StackLayout>
    </ContentPage.Content>
</d:DialogBase>

这是应用加载时显示的第一页

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        ContainerRegistration.Register();

        try
        {
            // register main container navigation
            var mainPage = FreshPageModelResolver.ResolvePageModel<AdjustmentEditPageModel>();
            var mainNavigation = new FreshNavigationContainer(mainPage, NavigationContainerNames.DailyRunSheet);
            mainNavigation.BarBackgroundColor = Color.FromRgb(0, 69, 140);
            mainNavigation.BarTextColor = Color.White;

            MainPage = mainNavigation;
        }
        catch (Exception ex)
        {
        }
    }

}

1 个答案:

答案 0 :(得分:2)

您需要使用:

         <StackLayout Spacing="0">
            <BoxView BackgroundColor="Green" />
            <ContentPresenter VerticalOptions="FillAndExpand"
                              BackgroundColor="Red" />
        </StackLayout>