Binding UserControl unload event to ViewModel

…衆ロ難τιáo~ 提交于 2019-12-22 01:17:39

问题


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 ?


回答1:


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


来源:https://stackoverflow.com/questions/7137713/binding-usercontrol-unload-event-to-viewmodel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!