ICollectionView with .net core 3.0

北慕城南 提交于 2021-01-29 08:40:21

问题


I'm migrating my project from classic .net to .net core 3.0. I use in my viewmodel ICollectionView interface and it is not recognized in .net core 3.0 framework.

I added several nuget packages to attempt to make it work, but with no luck.

Microsoft claims System.ComponentModel defines icollectionview (https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.icollectionview?view=netcore-3.0), but it is not found. I also tried to include windowsbase, but it's not found either.

Is my environment faulty ? Did I miss something ?

Thanks for your help.

Here is a small class to compile under a .netcore3 project:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        ICollectionView col =new CollectionViewSource().View;
        col.Filter = null;
        col.Refresh();
    }
}

Edit:

Thanks to ALFA for Microsoft.Windows.SDK.Contracts which offer an ICollectionView interface on .net core, but unfortunatly, it is not complete: Filter and refresh are not implemented.


回答1:


You need to edit your project file YourProjectName.csproj from this:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
   <TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

To this:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
   <TargetFramework>netcoreapp3.0</TargetFramework>
   <UseWPF>true</UseWPF>
</PropertyGroup>

It helps to me.




回答2:


On .NET Core 3.0+ you can install the Microsoft.Windows.SDK.Contracts package which includes all the supported Windows Runtime APIs up to Windows 10 version 1903, and will let you use ICollectionView.

The Windows 10 WinRT API Pack enables you to add the latest Windows Runtime APIs support to your .NET Framework 4.5+ and .NET Core 3.0+ libraries and apps.




回答3:


have tried importing the DLL into your .Core project ?

https://docs.microsoft.com/es-es/dotnet/api/system.windows.data.collectionview?view=netframework-4.8

You can find the PresentationFramework.dll DLL in the .Net folder,In my case I have it in


    C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF



来源:https://stackoverflow.com/questions/58298028/icollectionview-with-net-core-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!