Quicknote: Binding XAML event to ViewModel

Just a rough note. I was building a WPF interface for a tool i’ve written. I wanted to bind events on this to my ViewModel, instead of have classic “code beside”.

Other than using third party code, the quickest way to do this was to reference the System.Windows.Interactivity.dll. This is part of the Microsoft Expression Blend SDK http://www.microsoft.com/en-us/download/details.aspx?id=3062

I then added a namespace reference as follows: xmlns:i=”http://schemas.microsoft.com/expression/2010/interactivity

I could then bind an even to a property in my ViewModel and thus handle the event there. 

    <i:EventTrigger EventName="IsVisibleChanged">
      <i:InvokeCommandAction Command="{Binding VisibleChanged}"/>

Related link: http://msdn.microsoft.com/en-us/library/gg405484(v=PandP.40).aspx