microsoft-ui-xaml
microsoft-ui-xaml copied to clipboard
ListBox and ListView don't listen for INotifyCollectionChanged if the type implements a generic IList<T> interface; it *must* be the legacy IList.
Describe the bug ListBox/ListView require ItemsSource to impliment the legacy IList interface. IList<T> is not supported by WinRT. It should be possible to support cases where the the ItemsSource only impliements IEnumerable and INCC
Internal bug - https://microsoft.visualstudio.com/OS/_queries/edit/24511651
Is this related to https://github.com/microsoft/microsoft-ui-xaml/issues/931 then as well?
related but solvable differently. I think the issue here is that we want collection controls to be able to work with just IEnumerable + INCC. If WinRT supported generics, then collection controls don't have to depend on the 'IList' interface.
Just hit this again, been scratching my head for hours on why my custom collection with just INotifyCollectionChanged
wasn't triggering the ListViewBase
to update its view of my collection items... ☹
@michael-hawker, what list interfaces does your collection implement?
@MikeHillberg originally it was just IEnumerable<object>
and INotifyCollectionChanged
, adding IList
fixed the problem, but meant I had to add more implementation details (which I may have needed anyway in the future, but was testing out the basics first).
And it looks like IList but not IList<T>. IEnumerable or IEnumerable<T> should be enough.
@MikeHillberg, yeah that's what I was expecting initially, but it would only listen to updates once it was an IList
.
The problem I'm running into now is that if I don't raise the right NotifyCollectionChangedEventArgs
than ListView tries to add an existing container to itself and I get an unhandled exception with a duplicate item in the tree.
Is this process documented anywhere with examples of what items adding/moving/removing in the collection should correspond to event args and how ListView updates its containers? I also think I'm running into issues with performing multiple operations on the collection and needing to give ListView one event to modify the containers?
I agree with @MikeHillberg. NotifyCollectionChangedEventArgs
contains not only NewStartingIndex
and OldStartingIndex
properties, but also NewItems
and OldItems
lists. This is enough to properly handle all changes by the INCC interface consumer.
I've checked it and currently (AppSDK 1.1.4) uses IList[index]
to obtain the item located at NewStartingIndex
. So you are out of luck if you try to use something like ConcurrentQueue<T>
as a backing item collection.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.