我在 Xamarin.Forms 中创建了一个页面,该页面应显示一些来自 IList 数据源的项目,以及它们后面的视频。
项目列表将使用列表视图显示。视频使用视频视图显示。
这是实际的页面代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mm="clr-namespace:Plugin.MediaManager.Forms;assembly=Plugin.MediaManager.Forms"
x:Class="MyApp.Views.ItemDetailPage"
Title="{Binding Title}">
<ScrollView>
<StackLayout Orientation="Vertical" Padding="15">
<ListView
ItemsSource="{Binding Item.Properties}"
HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10">
<Label Text="{Binding .}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="16" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<mm:VideoView x:Name="MyVideo" WidthRequest="320" HeightRequest="190" HorizontalOptions="FillAndExpand" />
<Button x:Name="BtnPlayStop" Text="Iniciar" Clicked="PlayStop_Clicked" BackgroundColor="Silver" TextColor="White"/>
</StackLayout>
</ScrollView>
</ContentPage>
运行该应用程序时遇到的问题是:
- 页面最初显示为向下滚动,以便最初看到视频。
- 列表视图的最后一个元素和视频之间的空间非常大
- 使用手指很难向上或向下滚动。
我的 XAML 代码是否正确? 我可以应用哪些更改来修复这种奇怪的行为?
编辑:我发现列表视图和视频之间什么都不是。这就是为什么很难滚动的原因。如果我将手指放在列表视图中,我可以滚动,如果我将手指放在视频或按钮内也是如此。但是,如果我将手指放在列表视图和视频之间,则不会执行滚动。很奇怪,不是吗?
谢谢 海梅
最后,我在此页面中使用了解决方案:https://xamarinsharp.com/2017/05/16/listview-height-issue-in-xamarin-forms-how-to-solve-it/
基本上,就是根据绑定元素的数量,在代码中设置ListView的HeightRequest。
问候
海梅