XAML 使用xamarinForms在listView上显示问题

u1ehiz5o  于 2023-04-27  发布在  其他
关注(0)|答案(1)|浏览(146)

这是我的XAML源代码:

<ScrollView VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Margin="20,0,20,0">
                <ListView x:Name="listViewm" ItemsSource="{Binding MySource}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <Grid BackgroundColor="LightGray" Padding="1">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="1*" />
                                        <ColumnDefinition Width="1*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="1*" />
                                        <RowDefinition Height="1*" />
                                        <RowDefinition Height="1*" />
                                    </Grid.RowDefinitions>
                                    <Label Grid.Column="0" Grid.Row="0" Text="{Binding x}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#E9EDF2" TextColor="Black" HorizontalTextAlignment="Center" Margin="1"></Label>
                                    <Label Grid.Column="1" Grid.Row="0" Text="x" VerticalOptions="FillAndExpand"  HorizontalOptions="FillAndExpand" BackgroundColor="#E9EDF2" TextColor="Black" HorizontalTextAlignment="Center" Margin="1"></Label>
                                    <Label Grid.Column="1" Grid.Row="1" Text="y" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#E9EDF2" TextColor="Black" HorizontalTextAlignment="Center" Margin="1"></Label>
                                    <Label Grid.Column="0" Grid.Row="1" Text="{Binding y}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#E9EDF2" TextColor="Black" HorizontalTextAlignment="Center" Margin="1"></Label>
                                    <Label Grid.Column="1" Grid.Row="2" Text="z" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#E9EDF2" TextColor="Black" HorizontalTextAlignment="Center" Margin="1"></Label>
                                    <Label Grid.Column="0" Grid.Row="2" Text="{Binding z}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#E9EDF2" TextColor="Black" HorizontalTextAlignment="Center" Margin="1"></Label>
                                </Grid>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </ScrollView>

我无法修复显示。这是运行时显示的列表。有解决方案吗?
enter image description here
谢谢

0aydgbwb

0aydgbwb1#

您可以尝试设置HasUnevenRows属性:

<ListView x:Name="listViewm" ItemsSource="{Binding MySource}" HasUnevenRows="True">

有关详细信息,您可以参考ListView外观。
希望能成功。

相关问题