Xamarin.forms 在CollectionView中选择项目时如何播放动画?

Xamarin.forms 在CollectionView中选择项目时如何播放动画?,xamarin.forms,Xamarin.forms,我有以下CollectionView: 我决定为所选项目设置动画会很酷,所以我添加了TapGestureRecognitor。 它指向的事件只是将煎饼视图向下缩放,然后再向上缩放 完成后,我绑定了CollectionView的SelectedItem和SelectionChangedCommand SelectedItem=“{Binding SelectedBrand}”SelectionChangedCommand=“{Binding BrandSelected}” SelectionM

我有以下CollectionView:


我决定为所选项目设置动画会很酷,所以我添加了TapGestureRecognitor。 它指向的事件只是将煎饼视图向下缩放,然后再向上缩放

完成后,我绑定了CollectionView的SelectedItem和SelectionChangedCommand

SelectedItem=“{Binding SelectedBrand}”SelectionChangedCommand=“{Binding BrandSelected}”
SelectionMode=“Single”
然后,我了解到TapGestureRecognitor会阻止CollectionView的单击事件


如何在不阻止SelectionChangedCommand的情况下为SelectedItem的煎饼视图设置动画?

由于您使用了MVVM,因此可以直接处理ViewModel中的逻辑

1.定义PancakeView的子类 3.在xaml中

//...
4.在视图模型中 在SelectedBrand的集合方法中

  public YourModel SelectedBrand
    {
        get
        {
            return xxx;
        }

        set
        {
            if(value!=xxx)
            {
                xxx = value;
                OnPropertyChanged("SelectedBrand");
                MessagingCenter.Send<Object, int>(this,"tap", SelectedBrand.Id);
            }
        }
    }
public your model selected品牌
{
得到
{
返回xxx;
}
设置
{
如果(值!=xxx)
{
xxx=值;
房地产变更(“选定品牌”);
MessagingCenter.Send(此“点击”,选择Brand.Id);
}
}
}

工作起来很有魅力!谢谢!
public class YourModel
{
   public int Id {get;set;}
   
  // other properties
}

And set it as the index of ItemSource (0,1,2...)

<local:MyPancakeView Index="{Binding Id}" > 
 
   //...
  
</local:MyPancakeView>
  public YourModel SelectedBrand
    {
        get
        {
            return xxx;
        }

        set
        {
            if(value!=xxx)
            {
                xxx = value;
                OnPropertyChanged("SelectedBrand");
                MessagingCenter.Send<Object, int>(this,"tap", SelectedBrand.Id);
            }
        }
    }