我编写了一个代码,用于在ListView上显示数据列表。但是,当我在UWP和Android OS中部署此代码时,它们的行为是不同的。 UWP程序运行良好并显示所有列表数据。但是,Android输出在带有滚动选项的单个列表项中显示整个列表。
UWP输出:
Android输出:
我的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>
有没有人遇到过这个问题?
您的页面设置告诉它只创建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>