【发布时间】:2021-05-14 18:57:27
【问题描述】:
我有一个ListView,其中包含大约 10 个项目。 ListView 需要在屏幕上完全显示。但它没有显示。尝试使用ScrollView,但是所有项目都没有显示,并且无法滚动到视图中的最后一项。
附上我的源代码供参考。 XAML 源代码
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="KFM.View.TripPage" Title="Trips" >
<ContentPage.Content>
<StackLayout Orientation="Vertical" Spacing="30" VerticalOptions="FillAndExpand">
<ScrollView VerticalOptions="FillAndExpand">
<ListView x:Name="MenuListView" ItemsSource="{Binding Trips}" HorizontalOptions="FillAndExpand" HasUnevenRows="True" SeparatorVisibility="None" IsEnabled="False" VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="5">
<Frame HasShadow="true" HeightRequest="100" BorderColor="Black">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackLayout Grid.Column="0" Orientation="Vertical" VerticalOptions="FillAndExpand">
<BoxView Color="Blue" VerticalOptions="FillAndExpand"/>
</StackLayout>
<StackLayout Grid.Column="1" Orientation="Vertical" VerticalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Label Text="{Binding DateFrom,StringFormat='{}{0:MMM - dd HH:mm}'}" TextColor="Black" FontSize="20"/>
<Label Text=" to " TextColor="Black" FontSize="20"/>
<Label Text="{Binding DateTo,StringFormat='{}{0:MMM - dd HH:mm}'}" TextColor="Black" FontSize="20"/>
</StackLayout>
<Label Text="Details" TextColor="Black" FontSize="16" TextDecorations="Underline"/>
<Label Text="{Binding Place}" TextColor="Black" FontSize="20"/>
</StackLayout>
</Grid>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
后端 C# 代码
Trips = new List<Trip>()
{
new Trip() { DateFrom = DateTime.Now, DateTo = DateTime.Now.AddDays(2), Place="Chennai to trichy" },
new Trip() { DateFrom = DateTime.Now.AddDays(7), DateTo = DateTime.Now.AddDays(9), Place="Chennai to bangalore" },
new Trip() { DateFrom = DateTime.Now.AddDays(12), DateTo = DateTime.Now.AddDays(14), Place="Local" },
new Trip() { DateFrom = DateTime.Now.AddDays(16), DateTo = DateTime.Now.AddDays(18), Place="Chennai to Salem" },
new Trip() { DateFrom = DateTime.Now.AddDays(18), DateTo = DateTime.Now.AddDays(22), Place="Chennai to Tirunelveli" },
new Trip() { DateFrom = DateTime.Now.AddDays(24), DateTo = DateTime.Now.AddDays(30), Place="Chennai to Mysore" },
new Trip() { DateFrom = DateTime.Now.AddDays(32), DateTo = DateTime.Now.AddDays(34), Place="Chennai to Tirunelveli" },
new Trip() { DateFrom = DateTime.Now.AddDays(36), DateTo = DateTime.Now.AddDays(40), Place="Chennai to Mysore" },
};
【问题讨论】:
-
没有显示是什么意思?什么都没有?不需要 ScrollView ListView 在需要时为您处理
-
Trips在哪里填充?如果在绑定发生后添加数据,它将不起作用。
标签: c# xaml xamarin.forms xamarin.forms.listview