❔ Custom ObservableCollection behaves differently on WPF
As in the image shown this is my error message.
The Collection i built, and use is found here: https://github.com/bPoller2810/MvvMHelpers/blob/main/MvvMHelpers.core/ConditionalObservableCollection.cs
This Collection works without any issues in Xamarin.Forms, Maui and other non Framework useage.
But in Wpf the error seen shows up. (every time). I Then created a mvp to recreate the error, but there it works.
Sadly i could not find out :
- Why does it talk about add, if i send "new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index)"
- Why does it fail anyway? (My Collection contains 1 element and my action is to type a letter that will get the element removed. this single removed element is on index 0)
- (Bonus) Why does it not fail in the mvp.
does anybody have an idea or deeper knownledge in wpf and can help me here?
15 Replies
When is it actually erroring (do you have that relevant code)?
Sure, here is the full code. The SearchTerm Property is bound to a TextBox. From The CollectionChanged Invoke on, its internal to wpf and i am not yet figured out stuff there
Index resolved to 0 and internal items only contains 1 element.
(my demo code uses strings instead of a model)
You said it was referencing your Add as well?
no. the error text says add.. wich is confusing as hell
the Stacktrace shows "Add" is not involved. sorry for my confusing phrasing
Ah yes just translated it, which sounds right as an added item wouldn't be at index 0, it would be at the end of the collection
yeah. that error is confusing, because it happens in a Remove action.
Just out of interest have you got the code for your RaiseCollectionAdd method? And the end of the line for RaiseCollectionRemove that's cut off?
se thi initial post there is the full source of the collection(link)
the index is not yet pushed that was my first solving attempt
https://github.com/dotnet/wpf/blob/562aa8c8d86153ad89b4dd98c9f73a822072e637/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/EnumerableCollectionView.cs#L431 this seems my error
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.24 Hours is pretty strict for stale. #server-feedback
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.$close
Use the /close command to mark a forum thread as answered
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.