如何在WPF MVVM中调用窗口的加载事件?

时间:2021-03-15 23:51:50

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

从OnLoaded()事件处理程序代码创建命令非常简单,但是如何从视图中调用它呢?

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

不再切蛋糕,因为它调用xaml.cs中的代码。如何创建一个ICommand等价文件?

2 个解决方案

#1


10  

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.

你可以通过附加行为来做这种事情。为了节省时间,我们来看看Marlon Grech的附加命令行为库。

#2


5  

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

您可以使用MVVM Light Toolkit的事件来命令行为:http://blog.galasoft.ch/archive/2009/11/05/mvm - Light - Toolkit -v3- alpha2 - eventtobehavior.aspx

#1


10  

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.

你可以通过附加行为来做这种事情。为了节省时间,我们来看看Marlon Grech的附加命令行为库。

#2


5  

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

您可以使用MVVM Light Toolkit的事件来命令行为:http://blog.galasoft.ch/archive/2009/11/05/mvm - Light - Toolkit -v3- alpha2 - eventtobehavior.aspx