Visual Studio 2017 - 表达式交互发生了什么?

Visual Studio 2017 - What happened to Expression interactions?

我广泛使用表达式交互的 CallMethodAction 以 MVVM 友好的方式处理来自 XAML 的事件。

我刚刚在 VS2017 中创建了一个新的 WPF 项目,现在我看到旧的 Expression 命名空间不见了。我发现 this page on MSDN 这是我正在寻找的操作,但在引用该程序集并添加名称空间后,它不包含 CallMethodAction。该页面适用于 Silverlight,而这是 WPF,因此我担心操作不再可用。

那么有人知道它是否真的 removed/replaced 吗?现在应该如何在视图模型上调用事件处理程序?

(我知道 InvokeCommandAction,但我更喜欢 CallMethodAction,因为它传递原始事件参数,并允许取消预览事件。)

编辑:为了继续前进,我尝试了 InvokeCommandAction,但它不再以同样的方式工作,而且我找不到任何关于新用法的文档。

我确实找到了 Microsoft.Xaml.Interactions 命名空间的 this reference on MSDN,它似乎包含我需要的 类,但该程序集似乎不存在。

我觉得我在这里遗漏了一些明显的东西。我看不出他们怎么能对像响应事件这样基本的东西做出重大改变。

CallMethodAction 在 Microsoft.Expressions.Interactions.dll 中定义。此程序集不是 .NET Framework 的一部分,但您可以使用 NuGet 下载它:https://www.nuget.org/packages/MicrosoftExpressionInteractions/

并且 InvokeCommandAction class 在 System.Windows.Interactivity.dll 程序集中定义:https://www.nuget.org/packages/System.Windows.Interactivity.WPF/

使用 Visual Studio 2017 安装程序安装 "Blend for Visual Studio SDK for .NET",您可以在 "Individual components" 页面的 "SDKs, libraries, and frameworks" 标题下找到它。

关于 2020 年的一点更新:

As mentioned by Jan in other question:

Microsoft 开源了 XAML 行为并发布了 blog post 如何更新到此版本。

继续更新的步骤:

  1. 删除对“Microsoft.Expression.Interactions”和“System.Windows.Interactivity”的引用。
  2. 安装 Microsoft.Xaml.Behaviors.Wpf NuGet 包。
  3. XAML 文件 – 替换 xmlns 命名空间 http://schemas.microsoft.com/expression/2010/interactivity and http://schemas.microsoft.com/expression/2010/interactions with http://schemas.microsoft.com/xaml/behaviors
  4. C# 文件 – 将 c# 文件中的用法“Microsoft.Xaml.Interactivity”和“Microsoft.Xaml.Interactions”替换为“Microsoft.Xaml.Behaviors”