我尝试在示例 WPF 应用程序中使用 DispatcherScheduler.Current,以下行无法解析该类(静态)。
有人知道为什么这不能解决吗?
public partial class App : Application
{
public App()
{
**var tmp = DispatcherScheduler.Current;**
}
}
csproj 文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Reactive" Version="5.0.0" />
</ItemGroup>
</Project>
GitHub 上的以下支持问题表明这应该有效 - here
操作系统:Mircosoft Windows 10 Pro, 版本:10.0.19042
最佳答案
我做了一个新的.NET 5 WPF项目,我看到了同样的问题。添加 nuget ReactiveUi
解决了缺少 DispatcherScheduler
的问题,但不知道为什么仅引用 System.Reactive
就无法使用 DispatcherScheduler
>.
更新:
我测试了新项目,但对于 .NET Core 3.1 WPF 来说一切正常。这是 .NET 5 的问题。
更新2:
我在github上发现问题https://github.com/dotnet/reactive/issues/1497 , DispatcherScheduler
可用于 TFM net5.0-windows10.0.19041
。我还使用 ILSpy 确保 System.Reactive.dll
对于 .net5.0
和 net5.0-windows10.0.19041
是不同的。< br/>
将 csproj
中的 TargetFramework
更改为:
<TargetFramework>net5.0-windows10.0.19041</TargetFramework>
解决问题。
关于c# - .Net 5.0 中对 WPF 的响应式扩展支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67518434/