[英]How to add System.Windows.Interactivity to project?
My project missing System.Windows.Interactivity
.我的项目缺少
System.Windows.Interactivity
。 Google says that I have to install Expression Blend, but on my other computer I have this library and I don't have Expression Blend installed. Google 说我必须安装 Expression Blend,但在我的另一台计算机上有这个库,但我没有安装 Expression Blend。 So there should be another way to obtain
System.Windows.Interactivity
?那么应该有另一种方法来获取
System.Windows.Interactivity
吗? What should I do?我应该怎么办? (right now i don't have another computer so I can not just copy this library:)
(现在我没有另一台电脑所以我不能只复制这个库:)
Although this issue is quite old, i think this is relevant news / the most recent answer: Microsoft open-sourced XAML Behaviours and posted a blog post how to update to this version: https://devblogs.microsoft.com/dotnet/open-sourcing-xaml-behaviors-for-wpf/虽然这个问题已经很老了,但我认为这是相关新闻/最新答案:Microsoft 开源 XAML 行为并发布了一篇博客文章如何更新到此版本: https : //devblogs.microsoft.com/dotnet/open -source-xaml-behaviors-for-wpf/
To save you a click, this is the main steps to migrate:为了节省您的点击,这是迁移的主要步骤:
The official package for behaviors is Microsoft.Xaml.Behaviors.Wpf
.行为的官方包是
Microsoft.Xaml.Behaviors.Wpf
。
It used to be in the Blend SDK (deprecated).它曾经在Blend SDK 中(已弃用)。
See Jan's answer for more details if you need to migrate.如果您需要迁移,请参阅Jan 的回答以了解更多详细信息。
There is a new NuGet package that contains the System.Windows.Interactivity.dll that is compatible with:有一个新的 NuGet 包,其中包含与以下兼容的 System.Windows.Interactivity.dll:
To install Expression.Blend.Sdk, run the following command in the Package Manager Console要安装 Expression.Blend.Sdk,请在包管理器控制台中运行以下命令
PM> Install-Package Expression.Blend.Sdk
http://www.nuget.org/packages/Expression.Blend.Sdk/ http://www.nuget.org/packages/Expression.Blend.Sdk/
The easiest way might be to get it from NuGet:最简单的方法可能是从 NuGet 获取它:
http://www.nuget.org/packages/System.Windows.Interactivity.WPF/ http://www.nuget.org/packages/System.Windows.Interactivity.WPF/
With Blend for Visual Studio , which is included in Visual Studio starting with version 2013, you can find the DLL in the following folder:使用Blend for Visual Studio (从 2013 版开始包含在 Visual Studio 中),您可以在以下文件夹中找到 DLL:
C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.5\Libraries
You will have to add the reference to the System.Windows.Interactivity.dll
yourself though, unless you use Blend for Visual Studio with an existing project to add functionality that makes use of the Interactivity namespace.不过,您必须自己添加对
System.Windows.Interactivity.dll
的引用,除非您将 Blend for Visual Studio 与现有项目一起使用以添加使用 Interactivity 命名空间的功能。 In that case, Blend will add the reference automatically.在这种情况下,Blend 将自动添加引用。
Sometimes, when you add a new library, in introduces a clashing version of System.Windows.Interactivity.dll
.有时,当您添加新库时,会引入
System.Windows.Interactivity.dll
的冲突版本。
For example, the NuGet package MVVM light
might require v4.2 of System.Windows.Interactivity.dll
, but the NuGet package Rx-XAML
might require v4.5 of System.Windows.Interactivity.dll
.例如,NuGet 包
MVVM light
可能需要System.Windows.Interactivity.dll
v4.2,但 NuGet 包Rx-XAML
可能需要System.Windows.Interactivity.dll
v4.5。 This will prevent the the project from working, because no matter which version of System.Windows.Interactivity.dll
you include, one of the libraries will refuse to compile.这将阻止项目工作,因为无论您包含哪个版本的
System.Windows.Interactivity.dll
,其中一个库都将拒绝编译。
To fix, add an Assembly Binding Redirect by editing your app.config
to look something like this:要修复,请通过编辑
app.config
来添加程序集绑定重定向,如下所示:
<?xml version="1.0"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Windows.Interactivity"
publicKeyToken="31bf3856ad364e35"
culture="neutral"/>
<bindingRedirect oldVersion="4.0.0.0"
newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
<appSettings>
<add key="TestKey" value="true"/>
</appSettings>
Don't worry about changing the PublicKeyToken
, that's constant across all versions, as it depends on the name of the .dll, not the version.不要担心更改
PublicKeyToken
,它在所有版本中都是不变的,因为它取决于 .dll 的名称,而不是版本。
Ensure that you match the newVersion
in your appConfig
to the actual version that you end up pointing at:确保您将
newVersion
中的appConfig
与您最终指向的实际版本相匹配:
Alternative solution is to modify your current Visual Studio installation in the Visual Studio Installer替代解决方案是在 Visual Studio 安装程序中修改您当前的 Visual Studio 安装
Win + R %ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vs_installer.exe
Win + R
%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vs_installer.exe
adding the Blend for Visual Studio SDK for .NET
'Individual component' under 'SDKs, libraries, and frameworks':在“SDK、库和框架”下添加
Blend for Visual Studio SDK for .NET
“Individual component”:
after adding this component
System.Windows.Interactivity
should appear in its regular location Add Reference/Assemblies/Extensions
.添加此组件后
System.Windows.Interactivity
应出现在其常规位置Add Reference/Assemblies/Extensions
。
It appears this would only work for VS2017 or earlier.看来这仅适用于 VS2017 或更早版本。 For later versions, please refer to other answers.
对于以后的版本,请参考其他答案。
I have had the exact same problem with a solution, that System.Windows.Interactivity
was required for one of the project in Visual Studio 2019, and I tried to install Blend for Visual Studio SDK for .NET
from Visual Studio 2019 Individual components, but it did not exist in it.我在解决方案中遇到了完全相同的问题,即 Visual Studio 2019 中的一个项目需要
System.Windows.Interactivity
,我尝试从 Visual Studio 2019 单个组件安装Blend for Visual Studio SDK for .NET
,但是它不存在于其中。
The consequence of that, I was not able to build the project in my solution with repetitive of following similar error on different XAML parts of the project:结果,我无法在我的解决方案中构建项目,并且在项目的不同 XAML 部分重复遵循类似的错误:
The tag 'Interaction.Behaviors' does not exist in XML namespace 'clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity'.
XML 命名空间“clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity”中不存在标记“Interaction.Behaviors”。
The above mentioned errors snapshot example
上面提到的错误快照示例
The solution , the way I solved it, is by installing Microsoft Expression Blend Software Development Kit (SDK) for .NET 4 from Microsoft.解决方案,我解决它的方式,是通过从 Microsoft 安装 适用于 .NET 4 的 Microsoft Expression Blend 软件开发工具包 (SDK) 。
Thanks to my colleague @felza, mentioned that System.Windows.Interactivity
requires this sdk, that is suppose to be located in this folder:感谢我的同事@felza,提到
System.Windows.Interactivity
需要这个 sdk,假设位于这个文件夹中:
C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.0
In my case it was not installed.就我而言,它没有安装。 I have had this folder
C:\\Program Files (x86)\\Microsoft SDKs
with out Expression\\Blend\\.NETFramework\\v4.0
folder inside it.我有这个文件夹
C:\\Program Files (x86)\\Microsoft SDKs
没有Expression\\Blend\\.NETFramework\\v4.0
文件夹。
After installing it, all errors disappeared.安装后,所有错误都消失了。
它在 MVVM Light 中,从MVVM Light 下载页面获取。
I got it via the Prism.WPF NuGet-Package.我是通过 Prism.WPF NuGet-Package 获得的。 (it includes Windows.System.Interactivity)
(它包括 Windows.System.Interactivity)
If you are working with MVVM Light you have to use the System.Windows.Interactivity Version 4.0
(the NuGet .dll wont work) that you can find under :如果您正在使用 MVVM Light,则必须使用
System.Windows.Interactivity Version 4.0
(NuGet .dll 不起作用),您可以在以下位置找到:
PathToProjectFolder\\Software\\packages\\MvvmLightLibs.5.4.1.1\\lib\\net45\\System.Windows.Interactivity.dll
Just add this .dll manually as Reference and it should be fine.只需手动添加这个 .dll 作为参考,它应该没问题。
I was getting the following error using Visual Studio 2019:我在使用 Visual Studio 2019 时遇到以下错误:
System.Windows.Markup.XamlParseException: 'Could not load file or assembly 'System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
System.Windows.Markup.XamlParseException: '无法加载文件或程序集'System.Windows.Interactivity,Version=4.5.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35'或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference.
定位的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040)'
(来自 HRESULT 的异常:0x80131040)'
Our project is using packages.config and had NuGet references to MVVMLightLibs 5.4.1.1
and System.Windows.Interactivity.WPF 2.0.20525
.我们的项目正在使用 packages.config 并且 NuGet 引用了
MVVMLightLibs 5.4.1.1
和System.Windows.Interactivity.WPF 2.0.20525
。
Guided by some of the other answers here, I realised the problem was a conflict between the version of the DLL that MVVMLight was using and the one our project was using.在此处的其他一些答案的指导下,我意识到问题在于 MVVMLight 使用的 DLL 版本与我们的项目使用的 DLL 版本之间存在冲突。 The solution was:
解决方案是:
System.Windows.Interactivity
.System.Windows.Interactivity
引用。packages\\MvvmLightLibs.5.4.1.1\\lib\\net45\\System.Windows.Interactivity.dll
.packages\\MvvmLightLibs.5.4.1.1\\lib\\net45\\System.Windows.Interactivity.dll
的引用。<dependentAssembly>
<assemblyIdentity name="System.Windows.Interactivity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
Use the following two NuGet packages使用下面两个NuGet包
1.Microsoft.Xaml.Behaviors.wpf 1.微软.Xaml.行为.wpf
2.Expression.Blend.Sdk.WPF 2.表达.混合.Sdk.WPF
Moreover while installing VS2022 see option to install blend sdk. click on the checkbox while installing.If you have not found that check box then tick the UWP and then you can see that option while installing VS 2022.此外,在安装 VS2022 时,请参阅安装 blend sdk 的选项。在安装时单击该复选框。如果您没有找到该复选框,则勾选 UWP,然后您可以在安装 VS 2022 时看到该选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.