EventToCommand not working for custom event for the controls inside DataTemplate

Aug 19, 2014 at 12:21 PM
While using MVVM Light, EventToCommand is not working for custom events. Let me explain my case with simple custom button example.

Initially, i have successfully added MVVM Light in my sample. I have created one custom event(named as CustomModelLoaded) in my custom button class. Then i placed my button in UserControl. Here, i did my binding to custom event with EventToCommand.

In MainWindow, i used DataTemplate to show that UserControl to particular TabItem Content. While switching to that particular tab, eventtocommand not working. In my custom button class, i raised my event from OnApplyTemplate method.

But the above scenario works fine, when i placed the usercontrol as direct content to TabItem. I don't know what i did wrong or is this issue? Help me to move further on this.

For sample, please download from following link:

https://mvvmlight.codeplex.com/workitem/7654
Coordinator
Aug 19, 2014 at 12:41 PM
Hi,

It's not an EventToCommand issue but rather an EventTrigger issue. EventTriggers (i.e. the trigger that reacts to an event) is only triggered by routed events, not by standard events.

Hope this helps,
Laurent
Aug 19, 2014 at 1:00 PM
Hi Ibugnion,

But the same EventToCommand working fine when placing the user control directly to TabItem content rather than DataTemplate.