Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将EventToCommand添加到TriggerActionCollection_C#_.net_Wpf_Mvvm_Mvvm Light - Fatal编程技术网

C# 无法将EventToCommand添加到TriggerActionCollection

C# 无法将EventToCommand添加到TriggerActionCollection,c#,.net,wpf,mvvm,mvvm-light,C#,.net,Wpf,Mvvm,Mvvm Light,我正在使用MVVM Light处理一个WPF项目,并尝试使用EventToCommand,但我收到一条错误消息,上面说: 无法将“EventToCommand”类型的值添加到“TriggerActionCollection”类型的集合或词典中。” 我正在使用.NET Framework 4.7.2和NuGet库Microsoft.Xaml.Behaviors.Wpf 我见过很多地方谈论http://schemas.microsoft.com/expression/2010/interactivi

我正在使用MVVM Light处理一个WPF项目,并尝试使用
EventToCommand
,但我收到一条错误消息,上面说:

无法将“EventToCommand”类型的值添加到“TriggerActionCollection”类型的集合或词典中。”

我正在使用.NET Framework 4.7.2和NuGet库Microsoft.Xaml.Behaviors.Wpf

我见过很多地方谈论
http://schemas.microsoft.com/expression/2010/interactivity
, 但据我所知,这是现在不赞成的,而且
http://schemas.microsoft.com/xaml/behaviors应改用

在mvvmlight.net的变更日志中,我发现:

事件命令- BL0004.005,程序集“GalaSoft.MvvmLight.Extras.WPF4”中的类型“EventToCommand”是使用旧版本的Blend SDK生成的,在Windows Presentation Framework 4项目中不受支持

我尝试过更改项目目标框架版本,但似乎没有什么不同

任何帮助都将不胜感激

<UserControl x:Class="DialogueTree.View.DialogueControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:local="clr-namespace:DialogueTree.View"
             xmlns:command="http://www.galasoft.ch/mvvmlight"
             mc:Ignorable="d" 
             d:DesignHeight="200" d:DesignWidth="200"
             MinHeight="200" MinWidth="200">


来自MvvmLight的
EventToCommand
操作基于旧版Blend SDK程序集

  • XML名称空间
    http://schemas.microsoft.com/expression/2010/interactivity
  • CLR名称空间
    System.Windows.Interactivity
事实上,这些已被弃用,并被您使用的开源XAML行为所取代。问题是这些程序集不兼容,因此您不能将MvvmLight提供的操作与XAML行为一起使用,反之亦然。我猜MvvmLight将来也会更新以使用这些行为。关于本主题

但是,您不需要
EventToCommand
,因为XAML行为包已经包含一个执行相同操作的命令:
InvokeCommandAction
。但是属性名称可能不同

<b:EventTrigger EventName="LostFocus">
   <b:InvokeCommandAction Command="{Binding Source={StaticResource Locator}, Path=DialogueControlVM.EndEditHeadline}"
                          CommandParameter="{Binding}"/>
</b:EventTrigger>

<b:EventTrigger EventName="LostFocus">
   <b:InvokeCommandAction Command="{Binding Source={StaticResource Locator}, Path=DialogueControlVM.EndEditHeadline}"
                          CommandParameter="{Binding}"/>
</b:EventTrigger>