关于具有.net core 3.0的c#:ICollectionView

ICollectionView with .net core 3.0

我正在将我的项目从经典.net迁移到.net core 3.0。
我在我的视图模型ICollectionView接口中使用,在.net core 3.0框架中无法识别它。

我添加了几个nuget软件包以尝试使其正常运行,但是没有运气。

Microsoft声称System.ComponentModel定义了icollectionview(https://docs.microsoft.com/zh-cn/dotnet/api/system.componentmodel.icollectionview?view=netcore-3.0),但未找到。
我也尝试包含Windowsbase,但也找不到。

我的环境有问题吗?我错过了什么吗?

感谢您的帮助。

这是一个可在.netcore3项目下编译的小类:

1
2
3
4
5
6
7
8
9
10
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        ICollectionView col =new CollectionViewSource().View;
        col.Filter = null;
        col.Refresh();
    }
}

编辑:

感谢ALFA for Microsoft.Windows.SDK.Contracts在.net核心上提供ICollectionView接口,但不幸的是,它还不完整:未实现过滤器和刷新。


您需要通过以下命令编辑项目文件YourProjectName.csproj

1
2
3
4
5
<Project Sdk="Microsoft.NET.Sdk">

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

为此:

1
2
3
4
5
6
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

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

对我有帮助。


尝试将DLL导入您的.Core项目吗?

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

您可以在.Net文件夹中找到PresentationFramework.dll DLL,就我而言,我在

中拥有它。

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


.NET Core 3.0+上,您可以安装Microsoft.Windows.SDK.Contracts程序包,该程序包包括Windows 10版本1903之前所有受支持的Windows运行时API,并允许您使用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.