简体   繁体   English

如何从 .net Core 3.1 dll (WPF) 访问 Dispatcher

[英]How to access the Dispatcher from a .net Core 3.1 dll (WPF)

I read: .NET Dispatcher, for .NET Core?我读到: .NET Dispatcher,用于 .NET Core?

I'm not able to apply both solution.我无法同时应用这两种解决方案。

  • Solution of JBSnorro: Unable to find how to switch to "Microsoft.NET.Sdk.WindowsDesktop". JBSnorro 的解决方法:无法找到如何切换到“Microsoft.NET.Sdk.WindowsDesktop”。
  • Solution of codevision: I use .net Core 3.1 instead of .net Core 3.0 and a .dll instead of .exe. codevision 的解决方案:我使用 .net Core 3.1 而不是 .net Core 3.0 和一个 .dll 而不是 .exe。 The result is结果是

在此处输入图像描述

Any idea how to access the Dispatcher from .net-core 3.1?知道如何从 .net-core 3.1 访问 Dispatcher 吗?

IMPORTANT Clemens solution works great.重要的 Clemens 解决方案效果很好。 Also, by reloading the project directly from Visual Studio has the advantage to tell you more about the problem hidden in your .csproj file.此外,通过直接从 Visual Studio 重新加载项目,可以告诉您更多有关隐藏在 .csproj 文件中的问题的信息。 I had unmatching UseWPF with UseWpf!我有无与伦比的 UseWPF 和 UseWpf!

The project file should look like this:项目文件应如下所示:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
    <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <UseWPF>true</UseWPF>
    </PropertyGroup>
</Project>

If the project is unloaded, use Reload Project from the content menu.如果项目已卸载,请使用内容菜单中的Reload Project

Since a visual studio update has broke my project file my side i decide post how this should be done in 2022.由于 Visual Studio 更新破坏了我的项目文件,我决定在 2022 年发布如何完成此操作。

just check this checkbox in project properties.只需在项目属性中选中此复选框。

在此处输入图像描述

then visual studio should rewrite your project file and add the framework wpf to your reference automaticaly.然后visual studio应该重写您的项目文件并将框架wpf添加到您的参考中。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM