View model event bind to button click

Sency picture Sency · Jan 15, 2012 · Viewed 7.4k times · Source

My Viewmodel has an event

public class TestViewModel 
{
    public event RoutedEventHandler Run;
}

I wanna trigger this event when user clicked on a button in view

How to bind this with a button in a view ?

Answer

H.B. picture H.B. · Jan 15, 2012

Routed events are meant for controls not view models, if you have something that should be executed upon a button click a command would be more suitable in my opinion, it can easily be bound to the Button.Command.