how to call a window's Loaded event in WPF MVVM?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 02:54:49

问题


It is easy enough to create a command from my OnLoaded() event handler code, but how do I call it from the View?

<window Loaded="onLoaded"> doesn't cut the cake anymore since it calls code in the xaml.cs. How would I create an ICommand equivalent?


回答1:


You can do this sort of thing via an attached behavior. To save yourself some time, take a looked at Marlon Grech's Attached Command Behavior library.




回答2:


You could use the MVVM Light Toolkit's event to command behavior: http://blog.galasoft.ch/archive/2009/11/05/mvvm-light-toolkit-v3-alpha-2-eventtocommand-behavior.aspx



来源:https://stackoverflow.com/questions/1222704/how-to-call-a-windows-loaded-event-in-wpf-mvvm

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