简体   繁体   English

Xamarin表单中ColumnSpan的奇怪行为

[英]Odd behaviour of ColumnSpan in Xamarin Forms

I have a content view with a grid defined inside. 我有一个内容视图,其中定义了一个网格。 The grid has three rows and two columns. 网格具有三行两列。 I have an image that should cover the both the columns in the first row , ie column span =2 but setting the column span as 2 doesn't cover the whole area and setting it as 3 does the job. 我有一张图像应该覆盖第一行中的两列,即列跨度= 2,但是将列跨度设置为2不能覆盖整个区域,而将其设置为3可以完成工作。 Is it because of any error in the way i have created the grid. 是因为我创建网格的方式中的任何错误。 Below is the whole content view. 以下是整个内容视图。

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="GridView.HomeSliderComponent">
    <ContentView.Content>
        <Grid BackgroundColor="Black">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <Image Source="{Binding Cover}" Aspect="AspectFill" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"/>
            <Label Text="{Binding Title}" Grid.Row="1" Grid.Column="0" Margin="10,0,0,0" VerticalOptions="Center"/>
            <Label Text="{Binding Description}" Grid.Row="2" Grid.Column="0" VerticalOptions="Center" Margin="10,0,0,0"/>
            <Button Text="Resume Course" TextColor="#EBB53E" Grid.Row="2" Grid.Column="2" VerticalOptions="End" HorizontalOptions="End" Margin="5,5" BackgroundColor="Black" BorderColor="#EBB53E" BorderRadius="2" BorderWidth="2"/>
        </Grid>

    </ContentView.Content>
</ContentView>

The issue is, that your Button has Grid.Column="2" , which implictly creates a third column. 问题是您的Button具有Grid.Column="2" ,这隐式创建了第三列。 Hence your grid has 3 columns and you need Grid.ColumnSpan="3" in order to span the Image over the whole width. 因此,您的网格有3列,并且需要Grid.ColumnSpan="3"才能将Image覆盖整个宽度。

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

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