开发者

Binding UserControl unload event to ViewModel

开发者 https://www.devze.com 2023-03-29 09:03 出处:网络
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.

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 j开发者_Go百科ust want to use he generic .net 4.1 libraries.

Can some one show me how to accomplish this ?


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}" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号