This project is read-only.

So how can I hook up a RoutedEvent to a method in a ViewModel?

I borrowed a solution from MvvmLight here, as it fits very well.

Add these namespaces to your Xaml:

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:nomvvm="clr-namespace:NoMvvm;assembly=NoMvvm"

You'll of course, have to add a reference to System.Windows.Interactivity.  I included a version with NoMvvm.

Add this Xaml, to hook up a "Loaded" event to a method named "Refresh":

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <nomvvm:EventToCommand Command="{Binding Refresh}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

Easy peasy.

Last edited Aug 4, 2011 at 3:52 AM by jonathanpeppers, version 5

Comments

No comments yet.