C# 在CarrouselView中获取抽头元素的索引
我正在学习Xamarin,我想在我的CarouselView中获取被点击元素的idex 以下是Xaml代码:C# 在CarrouselView中获取抽头元素的索引,c#,xaml,xamarin.forms,C#,Xaml,Xamarin.forms,我正在学习Xamarin,我想在我的CarouselView中获取被点击元素的idex 以下是Xaml代码: <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" x:Name="currentPage"> <StackLayout > <CarouselView x:Name="TestList" > <CarouselView.ItemTemplate >
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
x:Name="currentPage">
<StackLayout >
<CarouselView x:Name="TestList" >
<CarouselView.ItemTemplate >
<DataTemplate>
<StackLayout >
<StackLayout Grid.Row="3" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding CarouselItemTapped,Source={x:Reference currentPage}}" CommandParameter="{Binding .}"/>
</StackLayout.GestureRecognizers>
</StackLayout>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</StackLayout>
属性将告诉您可见项的索引,并且是实际项。属性将告诉您可见项的索引,并且是实际项。让我们假设
ListWordsTest
是您的旋转木马视图的项源,然后我们可以通过以下方式获取索引:
CarouselItemTapped = new Xamarin.Forms.Command((selectItem) =>
{
var mynews = selectItem; //as IDoNotKnow I would like to get the item index
var index = ListWordsTest.IndexOf((TestModel)selectItem);
});
让我们假设
ListWordsTest
是您的旋转木马视图的项目源,然后我们可以通过以下方式获得索引:
CarouselItemTapped = new Xamarin.Forms.Command((selectItem) =>
{
var mynews = selectItem; //as IDoNotKnow I would like to get the item index
var index = ListWordsTest.IndexOf((TestModel)selectItem);
});
CarouselItemTapped = new Xamarin.Forms.Command((selectItem) =>
{
var mynews = selectItem; //as IDoNotKnow I would like to get the item index
var index = ListWordsTest.IndexOf((TestModel)selectItem);
});