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
Unfortunately, an
i:EventTriggeris not the same thing as anEventTrigger. The former is part of theSystem.Windows.Interactivityand the latter is a core part of WPF. SinceEventToCommandusesSystem.Windows.Interactivity, you’ll have to use a different mechanism thanStyle.Triggersto use it in a style. You can use my technique described in this StackOverflow answer: