如何在WPF MVVM中调用窗口的Loaded事件? [英] how to call a window's Loaded event in WPF MVVM?

查看:1423
本文介绍了如何在WPF MVVM中调用窗口的Loaded事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的OnLoaded()事件创建命令很容易 处理程序代码,但是如何从View中调用它?

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"> 不再切蛋糕了,因为 它在xaml.cs中调用代码.我将如何创建ICommand 等价的?

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

推荐答案

您可以通过附加行为来执行此类操作.为了节省时间,请看一下Marlon Grech的已附加命令行为库.

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.

这篇关于如何在WPF MVVM中调用窗口的Loaded事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆