Xamarin表单:CollectionView在ios中不起作用 [英] Xamarin Forms: CollectionView is not working in ios
问题描述
我将CollectionView
用于水平列表视图.它在android中工作正常,但在ios中,项目显示在另一个顶部.在下面附加屏幕截图:
I am using CollectionView
for the horizontal listview. It is working fine in android but in ios, the items are showing on one top of another. Attaching a screenshot below:
XAML
<CollectionView
HeightRequest="30"
SelectionMode="Single"
SelectionChanged="ItemTapped"
ItemsSource="{Binding Items}"
x:Name="collectionview"
ItemsLayout="HorizontalList">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Margin="5">
<Label
TextColor="Black"
FontSize="Large"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
Text="{Binding title}"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Xaml.cs
public async void ItemTapped(object sender, SelectionChangedEventArgs e)
{
var selectedItem = (e.CurrentSelection.FirstOrDefault() as MyModel);
if (selectedItem != null)
{
//Do action
}
}
在调用Forms.Init之前,在iOS的AppDelegate类和Android的MainActivity类中添加以下代码:
Add below code in AppDelegate class on iOS and MainActivity class on Android, before calling Forms.Init:
Forms.SetFlags("CollectionView_Experimental");
我在IOS中缺少什么吗?
Am I missing something in IOS?
推荐答案
似乎是Xamarin.Forms的现有问题.解决方法是,您可以将Xamarin.Forms的版本更新为4.4 pre2.
It seems an existing issue of Xamarin.Forms . As workaround you can update the version of Xamarin.Forms to 4.4 pre2 .
您可以检查Xamarin.forms 发行说明.
And you can check the Xamarin.forms release notes .
这篇关于Xamarin表单:CollectionView在ios中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!