-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] CarouselView Throws when removing an item. #10865
Comments
I have tried to reproduce the issue without success. Attached the sample created: @wrkettlitz Probably we are doing something different, could you review/update the attached sample or attach a reproduction sample? |
Reproduceable project:https://github.com/haavamoa/GithubIssues/tree/master/src/CarouselViewObservableCollection IntroductionI have noticed that this happens if you have the following case:
GIFSteps to reproduce:
WorkaroundDo a check to see if the ObservableCollection is empty when you remove the last item, if it is, you can new the ObservableCollection so it's ready to add later without exceptions.
Information:Xamarin Forms Version: 4.6.0.800 |
The workaround does not work as you will have to raise property changed when you new that up again, and the moment I do that I get the same exception. |
Okay, @jsuarezruiz , I've figured out what @wrkettlitz probably ment with the app crashing if he removed an item. Repruceable stepsIf you do the following with the same reproduceable project:
Real life example:I noticed this in a app today when I implemented a way for the user to rearrange the items in the Scenario:If the user was at the last item in the |
The same issue, any solution?? |
any update about this issue? I got same problem.
|
I'm getting this too. |
I get this fairly regularly if removing multiple items from the ObservableCollection backing the CarouselView ItemsSource. I even tried deferring the removal of items until they were scrolled to but it still threw this exception. |
I'm having this same problem on Xamarin Forms 4.8.0.1451. Right now, what works for me is to not raise a property changed when I remove the last item from the carousel view itemsource, and have a default Label on top of the carousel display to say something like "No Item to Show". |
It happens too on XF 4.5.0.725 |
Is this fixed in v5.0 ? |
@volcano619 should be fixed on pre4 |
It seems that as of version 5.0.0.2012 this problem still exists? Whenever I try to remove an item from the carouselview on android I get the argument out of range exception. |
As saw the solution for this,i tried to set carouselView.Position = 0 when CarouselView_PropertyChanged and CarouselView_CurrentItemChanged, also do not set EmptyViewProperty here,and it works for me |
The same for me Vs. 5.x
|
@rmarinho still present |
I got the same problem. It crashes when you delete the last item if that is visible but somehow it doesn't crash when there is only one item. I found a working workaround that is not mentioned here. If I want to remove the last item I first move the CarouselView 1 item back and do the deletion after some delay. In code it looks like: // CarView is my CarouselView
// Items is an ObservableCollection that is assigned to CarView.ItemsSource
// this is one item in Items that tries to deleted itself
int index = Items.IndexOf(this);
if (index == -1)
{
// somehow this is not found
return;
}
if (index > 0 && this == Items[^1])
{
// hack to prevent crash when removing last item
// see: https://github.com/xamarin/Xamarin.Forms/issues/10865
CarView.CurrentItem = Items[index - 1];
await Task.Delay(100);
}
// the actual deletion
Items.RemoveAt(index); edit: |
Still exists here |
The issue is closed but some people might still have nice crashes while changing ItemsSource on the fly. The crash is happening on ANDROID everytime you change the source being on another tab, then when you get back to the tab with carouselview (using xamarin app shell) the currentitem is used from the previous source, index becomes -1. You have actually several crashes incoming, if you bypass the one from index -1, yout get another one from currentItem not belonging to the new itemssource.
the extension method used:
|
Hi @taublast, The renderer works like a charm, thanks! |
For me it is still error.
Basically the erros is in class ObservableItemsSource.cs at method
|
Description
Steps to Reproduce
Expected Behavior
No error
Actual Behavior
ArgumentOutOfRangeException
Basic Information
Xamarin Forms 4.7.0.813-pre2
The text was updated successfully, but these errors were encountered: