.net 核心 3.0 的 ICollectionView

ICollectionView with .net core 3.0

我正在将我的项目从 classic .net 迁移到 .net core 3.0。 我在我的视图模型中使用了 ICollectionView 界面,但在 .net core 3.0 框架中无法识别它。

我添加了几个 nuget 包来尝试让它工作,但没有成功。

Microsoft 声称 System.ComponentModel 定义了 icollectionview (https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.icollectionview?view=netcore-3.0),但未找到。 我也试过包含windowsbase,但也没找到。

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

感谢您的帮助。

这里是在.netcore3项目下编译的小class:

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

编辑:

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

.NET Core 3.0+ 上,您可以安装 Microsoft.Windows.SDK.Contracts 软件包,其中包括所有受支持的 Windows 运行时 API,最高为 Windows 10 版本 1903,并允许您使用 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.

是否尝试过将 DLL 导入您的 .Core 项目?

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

您可以在 .Net 文件夹中找到 PresentationFramework.dll DLL,在我的例子中,我在


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

您需要编辑您的项目文件 YourProjectName.csproj 来自:

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

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

为此:

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

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

对我有帮助。