首页 > 解决方案 > 如何摆脱 Xamarin Forms 中网格行之间的空白行

问题描述

请注意此图像中第 0 行和第 1 行之间的空白(深蓝色)线...

在此处输入图像描述

我不确定这一行是从哪里来的,但是我该如何摆脱它,这样两行之间就没有间距了?

这是 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:control="clr-namespace:WP.MobileMidstream.Device.Pages"
             x:Class="WP.MobileMidstream.Device.Pages.LoginPage"             
             Visual="Material">
    <ContentPage.Resources>
        <Style x:Key="HeaderStyle" TargetType="Grid">
            <Setter Property="BackgroundColor" Value="#00458C" />
        </Style>
    </ContentPage.Resources>
    <ContentPage.Content>
        <Grid Style="{StaticResource HeaderStyle}" 
              Padding="0"
              Margin="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="23" />
                <RowDefinition Height="56" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <BoxView Color="Red" 
                     Grid.Row="0"
                     Grid.Column="0"                      
                     Grid.ColumnSpan="2" 
                     Margin="0" />
            <Label Grid.Row="1"
                   Grid.Column="0"
                   Grid.ColumnSpan="2"
                   VerticalTextAlignment="Center"
                   HorizontalTextAlignment="Center"
                   BackgroundColor="RosyBrown"
                   Margin="0"
                   FontSize="20"
                   TextColor="White">Daily Run Sheet</Label>
            <Image Source="hamburger_icon" 
                   Margin="10, 0, 0, 0"
                   Grid.Row="1"
                   Grid.Column="0" />
        </Grid>
    </ContentPage.Content>
</ContentPage>

标签: xamarinxamarin.forms

解决方案


我认为您对第二行的 ColSpan 和 Column 分配有误:

 <Label Grid.Row="1"
               Grid.Column="1"
               VerticalTextAlignment="Center"
               HorizontalTextAlignment="Center"
               BackgroundColor="RosyBrown"
               Margin="0"
               FontSize="20"
               TextColor="White">Daily Run Sheet</Label>
        <Image Source="hamburger_icon" 
               Margin="10, 0, 0, 0"
               Grid.Row="1"
               Grid.Column="0" />

更新: 尝试在网格上将 RowSpacing 设置为 0。


推荐阅读