【发布时间】:2020-06-26 21:46:20
【问题描述】:
我需要一个列表中的长按和短按
我正在使用长按列表中的项目的效果(ListView/CollectionView)但是当它起作用时,短按(点击)不起作用!
我的问题是:我是否需要创建另一个短点击效果版本,还是我可以同时拥有两者?我到处搜索,没有任何信息可以帮助我找到解决方案...
我一直在玩这个code in my repository,但无法同时工作。
<CollectionView
x:Name="carsCollection"
ItemsSource="{Binding Cars}"
SelectionMode="Single"
SelectionChangedCommand="{Binding TapCommand}"
SelectionChangedCommandParameter="{Binding Source={x:Reference carsCollection}, Path=SelectedItem}"
BackgroundColor="Orange">
<CollectionView.ItemTemplate>
<DataTemplate>
<ContentView>
<StackLayout
effects:LongPressedEffect.Command="{Binding Path=BindingContext.LongTapCommand, Source={x:Reference ThisPage}}"
effects:LongPressedEffect.CommandParameter="{Binding .}">
<Label Text="CollectionView: Long Press works but not normal selection" />
<StackLayout.Effects>
<effects:LongPressedEffect />
</StackLayout.Effects>
</StackLayout>
</ContentView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
包含命令的 ViewModel 是here。
【问题讨论】:
标签: xaml xamarin.forms xamarin.forms.listview