[英]Xamarin.Forms CollectionView API not tappable with SelectionChangedCommand
我有一個具有 SelectionChangedCommand 屬性的 CollectionView。 我想允許單元格導航到TAP上的不同頁面。 相反,當我點擊單元格時,什么也沒有發生。 如果我將手指放在單元格上並向任何方向移動,就會觸發預期的動作。
看法:
<views:CollectionViewExt
HeightRequest="170"
WidthRequest="200"
SelectionMode="Single"
SelectedItem="{Binding SlectedItem}"
ItemsSource="{Binding ItemList}"
BackgroundColor="Green"
SelectionChangedCommand="{Binding ItemSelectedCommand}">
視圖模型:
public TrackingItem SlectedItem { get; set; }
public ICommand ItemSelectedCommand
{
get
{
return new SingleTapCommand<Item>(async e =>
{
SlectedItem = e; // this is to reset the selected item.
await DifferentPage();
});
}
}
同樣,這可以通過非常困難、緩慢、長時間的滑動(甚至不認為它是點擊)導航到“DifferentPage”,因為它更像是滑動。 當我想讓它在 Tap 上導航到“不同頁面”時。
誰能幫我解決這個問題? 有沒有人遇到過同樣的問題?
這已經在所有 iOS 平台上進行了測試。
我寫了一個演示,點擊命令對我來說效果很好。 我將在下面分享我的代碼,希望您能從中得到一些想法:
我認為您需要檢查以下幾點:
DifferentPage
的代碼SingleTapCommand
在后面的代碼中:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
viewModel vm = new viewModel();
vm.navigation = Navigation;
BindingContext = vm;
}
}
public class viewModel {
public INavigation navigation;
public ICommand ItemSelectedCommand
{
get
{
return new Command(async e =>
{
// this is to reset the selected item.
await navigation.PushAsync(new Page1());
});
}
}
public viewModel() {
}
}
在 Xaml 中:
<CollectionView BackgroundColor="Green"
SelectionMode="Single"
SelectionChangedCommand="{Binding ItemSelectedCommand}">
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Baboon</x:String>
<x:String>Capuchin Monkey</x:String>
<x:String>Blue Monkey</x:String>
<x:String>Squirrel Monkey</x:String>
<x:String>Golden Lion Tamarin</x:String>
<x:String>Howler Monkey</x:String>
<x:String>Japanese Macaque</x:String>
</x:Array>
</CollectionView.ItemsSource>
</CollectionView>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.