-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove item from collection throws exception #12
Comments
What package are you using this on? Silverlight or the PCL one? Your code example seems to work fine with full .Net |
WPF .NET 4.5. The exception occurs when I put ObservableView as ItemsSource for ItemsControl.
|
Okay. Pinned down. Looks like I never implemented any sort of index space translation in the WhereOperation. And for whatever reason you hit a circumstance that I never tested. Which seems weird as this is fairly obvious. This is going to be a pretty hard problem to solve properly all around. Your solution allows items to come and go from the underlying collection, and then the item index that was removed from the underlying collection gets passed through unchanged into the Where operation, and then out of the Where operation. This doesn't work if the Where operation is actually removing objects. Because if so, the index of the items being filtered won't match the index of the items that are returned from the filter. I'll see if I can come up with some sort of solution. |
So, a temporary option for you might be to turn your query into an ObservableBuffer by invoking .ToBuffer() on the ObservableView. This basically wraps the ObservableView in a collection that maintains a final list of all the results, and updates it in response to events in the ObservableView, instead of simply proxying collection changed events. That final collection will raise events with indexes properly. |
Thanks for help. ToBuffer() solved it for me. |
When I try to remove item from original collection I'm getting exception:
"Collection Remove event must specify item position."
Managed to get around with new methods:
And in WhereOperation calling
NotifyCollectionChangedUtil.RaiseRemoveEvent(OnCollectionChanged, oldItems**, args.OldStartingIndex**);
The text was updated successfully, but these errors were encountered: