AndreiMisiukevich / CardView

CardsView | CarouselView | CoverflowView | CubeView for Xamarin.Forms
MIT License
710 stars 114 forks source link

CurrentItem doesn't refresh if the ItemsSource collection is edited #343

Closed Tommigun1980 closed 4 years ago

Tommigun1980 commented 4 years ago

Hi, and thanks for a great component!

I found this issue where the card view's CurrentItem doesn't update if the currently active card is removed from the ItemsSource. I haven't verified but I guess the same thing will happen if a card is added to the collection before the current card.

I added the following workaround to my code for now:

        public void HackRefreshCardsViewCurrentItem()
        {
            object selectedItem = null;
            int index = 0;
            foreach (var item in this.cards.ItemsSource)
            {
                if (index++ == this.cards.SelectedIndex)
                {
                    selectedItem = item;
                    break;
                }
            }
            this.cards.SelectedItem = selectedItem;
        }

... which I call whenever I change the card view's ItemsSource (ie it forcefully refreshes the SelectedItem).

Would be great if this was fixed so I could remove my hack! My card view is in the PanCardView mode.

Thanks so much!

AndreiMisiukevich commented 4 years ago

v.2.5.1

Tommigun1980 commented 4 years ago

Wow, so fast and it works perfectly now! Thanks so much Andrei 👍

AndreiMisiukevich commented 4 years ago

Wow, so fast and it works perfectly now! Thanks so much Andrei 👍

you are welcome)