_From @ebolefeysot on Wednesday, October 9, 2019 12:29:25 PM_
Despite what documentation on page https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.icollectionview?view=netcore-3.0 claims, this interface is not found in the nuget package for .net core 3.0.
Microsoft.Windows.SDK.Contracts offers an ICollectionView interface on .net core, but unfortunatly, it is not complete: Filter and refresh are not implemented.
Sample to compile:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
ICollectionView v =new CollectionViewSource().View;
v.Filter = null;
v.Refresh();
}
}
_Copied from original issue: dotnet/core#3578_
@ebolefeysot, this code compiles completely fine in a basic WPF application targeting .NET Core 3.0. Can you provide a sample WPF application where this fails to compile? Are you trying to use this outside of a WPF application?
This may be more of a documentation issue. The documentation has:

But it's unclear that this refers to WPF's (Microsoft.WindowsDesktop.App's) copy of WindowsBase and not the facade assembly in Microsoft.NETCore.App.
No, it is in a library project migrared from a .net4.0 framework to netcore3. I get no errors in .net40, but can't find this interface anymore in .netcore30.
I agree with @rladuca, it's not clear that this refer to a wpf project. And componentModel can be included in the library, but without ICollectionView.
Anyway, I edited the csproj to switch to a wpf app and it works.
Is there a plan to include that in .netcore3 library projects ?
This library holds my viewmodels, any idea how to replace ICollectionView in a viewmodel to avoid declaring the library as wpf ?
ComponentModel is just the namespace, the assembly is WindowsBase which (as far as I know) is WPF specific. Whats the problem with declaring the WPF dependency, do you need to use ICollectionView on non-Windows platforms? Adding a usecase may help decide on how to priorize the issue.
According to this page: https://docs.microsoft.com/en-us/dotnet/standard/cross-platform/using-portable-class-library-with-model-view-view-model, viewmodel classes are not bound to specific platfom.
When migrating my solution to .net core, I decided to migrates my libraries to .net standard. I can do it for all of them, except the viemodel library, because of these collectionview classes which are not available.
Either these classes are missing and should be added, or it is not correct to use these classes in this context. I search the web for another solution, but didn't find anything obvious yet.
Do you know what is the recommended way to write a viewmodel using collections in a .net standard environment ?
Do you know what is the recommended way to write a viewmodel using collections in a .net standard environment ?
Don't use UI platform specific concepts, because this will always require a dependency on the UI platform. "Collection Views" are a WPF specific concept and only work there (i.e. there is logic necessary to understand the interface and interact with it, and the stock implementations of the interface are using WPF specific features like the Dispatcher).
Alternatively, if you only need to run on Windows and are ok with your viewmodels to be WPF-specific, make the library netcore3 and enable the WPF framework in the project to get the dependency.
There may still be value lifting the interface itself out of WPF, but considering that other UI frameworks don't implement or understand it, I don't know how much sense it makes. In particular adding yet another variant of collections to understand would be adding a lot of burden to other UI platforms.
Thats just my personal opinion, not speaking for the WPF team.
Don't use UI platform specific concepts, because this will always require a dependency on the UI platform. "Collection Views" are a WPF specific concept and only work there.
That's what I want to do, don't use UI platform specific concepts.
Now that I can't use collection views anymore, any idea of what I can use instead in my viewmodel collections ?
Again my personal opinion, but for ViewModels I'd use a collection implementing IList<T> and INotifyCollectionChanged. Depending on your needs you can either implement them yourself or use the stock implementations ObservableCollection<T> and ReadOnlyObservableCollection<T>. They are also subclassable if you want to add missing features like bulk updating (which is considered to be added but not yet available). More complex scenarios like filtering and sorting are supported by IBindingList and stock implementation BindingList<T>.
Thanks for you help. I will update my library.
Going to close this issue. I have filed an issue with the docs team to get future documentation changes to potentially differentiate between SDKs for .NET Core.
Thanks all for your inputs and discussion!
Most helpful comment
Again my personal opinion, but for ViewModels I'd use a collection implementing
IList<T>andINotifyCollectionChanged. Depending on your needs you can either implement them yourself or use the stock implementationsObservableCollection<T>andReadOnlyObservableCollection<T>. They are also subclassable if you want to add missing features like bulk updating (which is considered to be added but not yet available). More complex scenarios like filtering and sorting are supported byIBindingListand stock implementationBindingList<T>.