Xaml 如何在Xamarin.Forms中同时长按和短按列表项?
我需要列表中的长按和短按 我对列表中的项目使用长按效果(ListView/CollectionView),但当这起作用时,短按(点击)不起作用 我的问题是:我是否需要创建另一个短点击效果版本,或者我是否可以同时创建这两个版本?我到处搜索,没有任何信息来帮助我找到解决方案 我一直在玩弄这件事,却没能让两者同时工作Xaml 如何在Xamarin.Forms中同时长按和短按列表项?,xaml,xamarin.forms,xamarin.forms.listview,Xaml,Xamarin.forms,Xamarin.forms.listview,我需要列表中的长按和短按 我对列表中的项目使用长按效果(ListView/CollectionView),但当这起作用时,短按(点击)不起作用 我的问题是:我是否需要创建另一个短点击效果版本,或者我是否可以同时创建这两个版本?我到处搜索,没有任何信息来帮助我找到解决方案 我一直在玩弄这件事,却没能让两者同时工作 包含命令的ViewModel是 我的问题是:我是否需要创建另一个效果版本,即短点击,或者我是否可以同时拥有这两个版本?我到处搜索,没有任何信息来帮助我找到解决方案 您可以使用具有cl
包含命令的ViewModel是
我的问题是:我是否需要创建另一个效果版本,即短点击,或者我是否可以同时拥有这两个版本?我到处搜索,没有任何信息来帮助我找到解决方案
您可以使用具有click事件而不是stacklayout的控件来实现这一点
使长按跟随下面链接中的STPE。然后使用“单击事件”执行快照按压。
或者您可以使用轻触手势识别器。
我的问题是:我是否需要创建另一个效果版本,即短点击,或者我是否可以同时拥有这两个版本?我到处搜索,没有任何信息来帮助我找到解决方案
您可以使用具有click事件而不是stacklayout的控件来实现这一点
使长按跟随下面链接中的STPE。然后使用“单击事件”执行快照按压。
或者您可以使用轻触手势识别器。
在我的案例中,在ImageButton上使用效果有效:
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="sharedmodels:Photo">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ImageButton Source="{Binding ThumbnailUrl, Converter={StaticResource ImageLocalStorageUrlConverter}}"
Command="{Binding Source={x:Reference collectionView}, Path=BindingContext.SelectCommand}"
CommandParameter="{Binding .}"
effects:LongPressEffect.Command="{Binding Source={x:Reference collectionView}, Path=BindingContext.DeleteCommand}"
effects:LongPressEffect.CommandParameter="{Binding .}">
<ImageButton.Effects>
<effects:LongPressEffect/>
</ImageButton.Effects>
</ImageButton>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
在我的案例中,在ImageButton上使用效果有效:
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="sharedmodels:Photo">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ImageButton Source="{Binding ThumbnailUrl, Converter={StaticResource ImageLocalStorageUrlConverter}}"
Command="{Binding Source={x:Reference collectionView}, Path=BindingContext.SelectCommand}"
CommandParameter="{Binding .}"
effects:LongPressEffect.Command="{Binding Source={x:Reference collectionView}, Path=BindingContext.DeleteCommand}"
effects:LongPressEffect.CommandParameter="{Binding .}">
<ImageButton.Effects>
<effects:LongPressEffect/>
</ImageButton.Effects>
</ImageButton>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
您可以使用
TouchEffect
高度可定制的软件包(这是一个收集了大量非常酷的可重用/通用控件、效果、行为的软件包…)
使用示例,您甚至可以控制长按的持续时间(默认值为500毫秒):
此外,你可以应用动画和其他很多东西
资源
文档(正在工作)
回购
您可以使用高度可定制的软件包(该软件包收集了大量非常酷的可重用/通用控件、效果、行为…)中的
TouchEffect
使用示例,您甚至可以控制长按的持续时间(默认值为500毫秒):
此外,你可以应用动画和其他很多东西
资源
文档(正在工作)
回购
如果它回答了您的问题或您觉得它对您有帮助,请用一个提示告诉我,否则您可能会给我留下反馈/评论。对于使用此功能的任何人:您不能将长按与常规手势识别器结合使用。两者都需要使用工具箱。如果工具箱回答了您的问题或您发现它对您有帮助,请使用一个新的工具让我知道,否则您可能会给我留下反馈/评论。对于使用此工具的任何人:您不能将长按与常规手势识别器结合使用。两者都需要使用工具箱
<StackLayout
xct:TouchEffect.LongPressCommand="{Binding Path=BindingContext.LongTapCommand, Source={x:Reference ThisPage}}"
xct:TouchEffect.LongPressCommandParameter="{Binding .}"
xct:TouchEffect.LongPressDuration="2000"
xct:TouchEffect.Command="{Binding Path=BindingContext.TapCommand, Source={x:Reference ThisPage}}"
xct:TouchEffect.CommandParameter="{Binding .}">