ErickTreeTops
ErickTreeTops

Reputation: 55

Binding UserControl unload event to ViewModel

I'm reasonable new to MVVM and have a usercontrol as my View. I'd like to Bind the "unload" event of that control to a method in my ViewModel. To clean up stuff when the control is shutting down.

My search so far has only come up with xamples that require you to include some kind of toolkit or libraries from expression blend SDK. I just want to use he generic .net 4.1 libraries.

Can some one show me how to accomplish this ?

Upvotes: 1

Views: 3767

Answers (1)

Rachel
Rachel

Reputation: 132568

I've always used the code shown here to create an AttachedCommandBehavior. It doesn't require any extra libraries and can be used like this:

<local:MyControl 
    local:CommandBehavior.Event="Unloaded" 
    local:CommandBehavior.Command="{Binding ViewModelUnloadedCommand}" />

Upvotes: 1

Related Questions