设计时错误:“EventTrigger”类型的值无法添加到“TriggerCollection”类型的集合或字典中。
运行时错误:值“System.Windows.Interactivity.EventTrigger”不是类型“System.Windows.TriggerBase”,不能在此通用集合中使用
I want to assign the same command to all my buttons on my user control. I use MVVM Light and I have tried all combinations. I have also tried to use EventSetter, but this does not allow binding to a command in the ViewModel
Here is a sample of what I am trying to do:<Style x:Key="CalculatorButton" TargetType="telerik:RadButton">
<Setter Property="Margin" Value="2"/>
<Setter Property="Cursor" Value="Hand"/>
<Style.Triggers>
<i:EventTrigger EventName="Click">
<cmd:EventToCommand Command="{Binding ButtonClick}"/>
</i:EventTrigger>
</Style.Triggers>
</Style>
Design Time error: A value of type 'EventTrigger' cannot be added to a collection or dictionary of type 'TriggerCollection'.
Runtime Error: The value \"System.Windows.Interactivity.EventTrigger\" is not of type \"System.Windows.TriggerBase\" and cannot be used in this generic collection
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
不幸的是,
i:EventTrigger
与EventTrigger
不同。前者是 System.Windows.Interactivity 的一部分,后者是 WPF 的核心部分。由于EventToCommand
使用System.Windows.Interactivity
,因此您必须使用与Style.Triggers
不同的机制才能在样式中使用它。您可以使用我在 StackOverflow 答案中描述的技术:Unfortunately, an
i:EventTrigger
is not the same thing as anEventTrigger
. The former is part of theSystem.Windows.Interactivity
and the latter is a core part of WPF. SinceEventToCommand
usesSystem.Windows.Interactivity
, you'll have to use a different mechanism thanStyle.Triggers
to use it in a style. You can use my technique described in this StackOverflow answer: