首页 > 解决方案 > Xamarin Forms:网格增加单个自动换行上所有行的行高

问题描述

在我的 Xamarin Forms 视图中,当网格中的一行有自动换行时,它也会增加所有其他行的行高。我可以更改哪些属性以确保只有受影响的行增加了行高?

普通造型:

在此处输入图像描述

在“位置”上包装后的样式:

在此处输入图像描述

XAML:

<ScrollView>
    <StackLayout Padding="10" x:DataType="auctions:VehicleViewModel">
        <ActivityIndicator x:Name="ActivitySpinner" IsRunning="True" IsVisible="{Binding IsBusy}" />
        <Label Text="{Binding Error}" StyleClass="Error" IsVisible="{Binding ErrorVisible}" />
        
        <Label Text="Basic Details" StyleClass="HeaderGreen" IsVisible="{Binding IsNotBusy}" />
        <Grid IsVisible="{Binding IsNotBusy}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>

            <Label Text="Model" StyleClass="Label" Grid.Column="0" Grid.Row="0" />
            <Label Text="{Binding Vehicle.VehicleModel}" Grid.Column="1" Grid.Row="0" />
            <Label Text="Registration" StyleClass="Label" Grid.Column="0" Grid.Row="1" />
            <Label Text="{Binding Vehicle.Registration}" Grid.Column="1" Grid.Row="1" />
            <Label Text="Year" StyleClass="Label" Grid.Column="0" Grid.Row="2" />
            <Label Text="{Binding Vehicle.Year}" Grid.Column="1" Grid.Row="2" />
            <Label Text="Mileage (Kms)" StyleClass="Label" Grid.Column="0" Grid.Row="3" />
            <Label Text="{Binding Vehicle.Odometer}" Grid.Column="1" Grid.Row="3" />
            <Label Text="Supplier" StyleClass="Label" Grid.Column="0" Grid.Row="4" />
            <Label Text="{Binding Vehicle.Supplier}" Grid.Column="1" Grid.Row="4" />
            <Label Text="Location" StyleClass="Label" Grid.Column="0" Grid.Row="5" />
            <Label Text="{Binding Vehicle.Location}" Grid.Column="1" Grid.Row="5" />
            <Label Text="Gearbox" StyleClass="Label" Grid.Column="0" Grid.Row="6" />
            <Label Text="{Binding Vehicle.GearboxType}" Grid.Column="1" Grid.Row="6" />
            <Label Text="Colour" StyleClass="Label" Grid.Column="0" Grid.Row="7" />
            <Label Text="{Binding Vehicle.Colour}" Grid.Column="1" Grid.Row="7" />
            <Label Text="Interior Colour" StyleClass="Label" Grid.Column="0" Grid.Row="8" />
            <Label Text="{Binding Vehicle.InteriorColour}" Grid.Column="1" Grid.Row="8" />
            <Label Text="Financed By" StyleClass="Label" Grid.Column="0" Grid.Row="9" />
            <Label Text="{Binding Vehicle.FinancedBy}" Grid.Column="1" Grid.Row="9" />
            <Label Text="Trade Price" StyleClass="Label" Grid.Column="0" Grid.Row="10" />
            <Label Text="{Binding Vehicle.TradePrice, Converter={StaticResource Currency}}" Grid.Column="1" Grid.Row="10" />
            <Label Text="Retail Price" StyleClass="Label" Grid.Column="0" Grid.Row="11" />
            <Label Text="{Binding Vehicle.RetailPrice, Converter={StaticResource Currency}}" Grid.Column="1" Grid.Row="11" />
            <Label Text="New Price" StyleClass="Label" Grid.Column="0" Grid.Row="12" />
            <Label Text="{Binding Vehicle.NewPrice, Converter={StaticResource Currency}}" Grid.Column="1" Grid.Row="12" />
        </Grid>

标签: xamarin.forms

解决方案


尝试定义Auto高度:

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

这是Xamarin.Forms Grid 的文档,请检查和列段落。如文档中所述,您应尽量确保将尽可能少的行设置为自动大小。因此,仅将其用于受影响的行。


推荐阅读