Search code examples
mvvmcross

Is there anything like DeselectionChangedCommand


I have an UICollectionView with AllowsMultipleSelection = true, and I binded SelectionChangedCommand of MvxCollectionViewSource, but SelectionChangedCommand triggers only on selection. How can I bind deselection? Is there anything like DeselectionChangedCommand?


Solution

  • Thank you for answer, but it isn't firing with a null value on deselected. But I found solution:

    public class MvxCollectionViewDSSource: MvxCollectionViewSource
    {
    
        public MvxCollectionViewDSSource(UICollectionView collectionView)
            : base(collectionView)
        {
        }
    
        public MvxCollectionViewDSSource(UICollectionView collectionView,
            NSString defaultCellIdentifier)
            : base(collectionView, defaultCellIdentifier)
        {
        }
    
        public override void ItemDeselected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var item = GetItemAt(indexPath);
    
            var command = SelectionChangedCommand;
            if (command != null)
                command.Execute(item);
        }
    }