xamarin表单中的跨平台listview滑动
我正在寻找在ListView上跨平台滑动以执行操作,例如打开菜单或删除项目 有人实现过这样的场景吗?例如,我想在向左滑动项目时删除项目xamarin表单中的跨平台listview滑动,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我正在寻找在ListView上跨平台滑动以执行操作,例如打开菜单或删除项目 有人实现过这样的场景吗?例如,我想在向左滑动项目时删除项目 我需要支持所有平台:ios/droid/win最简单的方法是使用内置的上下文操作,这允许您在ios上滑动列表项或在Android上长按列表项时显示菜单项 <ListView x:Name="ContextDemoList"> <ListView.ItemTemplate> <DataTemplate>
我需要支持所有平台:ios/droid/win最简单的方法是使用内置的上下文操作,这允许您在ios上滑动列表项或在Android上长按列表项时显示菜单项
<ListView x:Name="ContextDemoList">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnMore" CommandParameter="{Binding .}"
Text="More" />
<MenuItem Clicked="OnDelete" CommandParameter="{Binding .}"
Text="Delete" IsDestructive="True" />
</ViewCell.ContextActions>
<StackLayout Padding="15,0">
<Label Text="{Binding title}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
如果两种平台都需要刷卡,或者在刷卡项目时需要执行操作(而不是显示菜单项),那么我建议使用SyncFucion的listview控件,它具有社区许可证,并且提供了更大的灵活性
<syncfusion:SfListView x:Name="listView" AllowSwiping="True">
<syncfusion:SfListView.LeftSwipeTemplate>
<DataTemplate x:Name="LeftSwipeTemplate">
<Grid>
<Grid BackgroundColor="#009EDA" HorizontalOptions="Fill" VerticalOptions="Fill" Grid.Column="0">
<Grid VerticalOptions="Center" HorizontalOptions="Center">
<Image Grid.Column="0"
Grid.Row="0"
BackgroundColor="Transparent"
HeightRequest="35"
WidthRequest="35"
Source="Favorites.png" />
</Grid>
</Grid>
</Grid>
</DataTemplate>
</syncfusion:SfListView.LeftSwipeTemplate>
</syncfusion:SfListView>
最简单的方法是使用内置的上下文操作,这允许您在iOS上滑动列表项或在Android上长按列表项时显示菜单项
<ListView x:Name="ContextDemoList">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnMore" CommandParameter="{Binding .}"
Text="More" />
<MenuItem Clicked="OnDelete" CommandParameter="{Binding .}"
Text="Delete" IsDestructive="True" />
</ViewCell.ContextActions>
<StackLayout Padding="15,0">
<Label Text="{Binding title}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
如果两种平台都需要刷卡,或者在刷卡项目时需要执行操作(而不是显示菜单项),那么我建议使用SyncFucion的listview控件,它具有社区许可证,并且提供了更大的灵活性
<syncfusion:SfListView x:Name="listView" AllowSwiping="True">
<syncfusion:SfListView.LeftSwipeTemplate>
<DataTemplate x:Name="LeftSwipeTemplate">
<Grid>
<Grid BackgroundColor="#009EDA" HorizontalOptions="Fill" VerticalOptions="Fill" Grid.Column="0">
<Grid VerticalOptions="Center" HorizontalOptions="Center">
<Image Grid.Column="0"
Grid.Row="0"
BackgroundColor="Transparent"
HeightRequest="35"
WidthRequest="35"
Source="Favorites.png" />
</Grid>
</Grid>
</Grid>
</DataTemplate>
</syncfusion:SfListView.LeftSwipeTemplate>
</syncfusion:SfListView>
您可以使用SwipeView并将其包装到列表视图中
<ListView
ItemsSource="{Binding Items}"
SelectionMode="None"
CachingStrategy="RecycleElement"
RowHeight="110"
HeightRequest="1000"
BackgroundColor="White"
IsPullToRefreshEnabled="True"
Refreshing="OnRefresh">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<SwipeView>
<SwipeView.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnTapped"
NumberOfTapsRequired="1" />
</SwipeView.GestureRecognizers>
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem
Text="Edit"
IconImageSource="edit_icon.png"
BackgroundColor="Green"
Invoked="OnEdit" />
<SwipeItem
Text="Delete"
IconImageSource="delete_icon.png"
BackgroundColor="Red"
Invoked="OnDelete" />
</SwipeItems>
</SwipeView.RightItems>
<SwipeView.Content>
:
</SwipeView.Content>
</SwipeView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
:
From:您可以使用SwipeView并将其包装到列表视图中
<ListView
ItemsSource="{Binding Items}"
SelectionMode="None"
CachingStrategy="RecycleElement"
RowHeight="110"
HeightRequest="1000"
BackgroundColor="White"
IsPullToRefreshEnabled="True"
Refreshing="OnRefresh">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<SwipeView>
<SwipeView.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnTapped"
NumberOfTapsRequired="1" />
</SwipeView.GestureRecognizers>
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem
Text="Edit"
IconImageSource="edit_icon.png"
BackgroundColor="Green"
Invoked="OnEdit" />
<SwipeItem
Text="Delete"
IconImageSource="delete_icon.png"
BackgroundColor="Red"
Invoked="OnDelete" />
</SwipeItems>
</SwipeView.RightItems>
<SwipeView.Content>
:
</SwipeView.Content>
</SwipeView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
:
发件人:谢谢您的建议。我试图找到比为控件购买许可证更开放的源代码。试着在两个平台上都刷一遍谢谢你的建议。我试图找到比为控件购买许可证更开放的源代码。尝试在两个平台上继续滑动