Xamarin中ListView的不同视图形成Android和UWP

问题描述 投票:0回答:1

我编写了一个代码,用于在ListView上显示数据列表。但是,当我在UWP和Android OS中部署此代码时,它们的行为是不同的。 UWP程序运行良好并显示所有列表数据。但是,Android输出在带有滚动选项的单个列表项中显示整个列表。

UWP输出:

enter image description here

Android输出:

enter image description here

我的XAML代码用于显示数据:

<ContentPage Title="Edit Data">
<ContentPage.Content>
    <TableView Intent="Menu" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand">
        <TableRoot>
            <TableSection>
                <ViewCell>
                    <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand">
                        <ListView SeparatorColor="OrangeRed" ItemsSource="{Binding Items}" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <ImageCell Text="" Detail="{Binding ., Converter={x:StaticResource TimeToTextValueConv}}" ImageSource="car.png" >
                                    </ImageCell>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </StackLayout>
                </ViewCell>
            </TableSection>
        </TableRoot>
    </TableView>
</ContentPage.Content>

有没有人遇到过这个问题?

c# xaml xamarin.forms xamarin.android xamarin.uwp
1个回答
0
投票

您的页面设置告诉它只创建1个单元格并在其中放置ListView。如果您想要Items列表,请仅使用ListView。不要将ListView放在TableView中。

修改代码

<ContentPage Title="Edit Data">
    <ListView SeparatorColor="OrangeRed" ItemsSource="{Binding Items}" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ImageCell Text="" Detail="{Binding ., Converter={x:StaticResource TimeToTextValueConv}}" ImageSource="car.png" />
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage>
© www.soinside.com 2019 - 2024. All rights reserved.