微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xamarin Forms:网格增加单个自动换行上所有行的行高

如何解决Xamarin Forms:网格增加单个自动换行上所有行的行高

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

普通样式:

enter image description here

在“位置”上换行后的样式:

enter image description here

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>

解决方法

尝试定义 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 的 docs,检查 Rows and columns 段落。 如文档中所述,您应尽量确保将尽可能少的行设置为自动大小。因此,仅将其用于受影响的行。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。