Silverlight 3 LoadedEvent 路由到 ViewModel

发布于 2024-08-15 12:08:34 字数 126 浏览 1 评论 0原文

我的客户正在尝试挂钩视图模型中的用户控件加载事件。基本上他们想知道控件加载事件何时在视图模型内触发。他们正在寻找一种无需 Xaml 背后的代码即可完成此操作的方法。这是否可行。我正在研究是否可以将加载的事件路由到 xaml 中的视图模型。

My client is trying to hook to a usercontrols Loaded Event in the View Model. Basically they want to know when the controls loaded event triggers inside the view model. They are looking for a way to do it without code behind the xaml. Is this even feasible. I am looking into whether I can route the loaded event to the viewmodel in the xaml.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫儰鉨ミ守葔 2024-08-22 12:08:34

一种方法是使用 InvokeDataCommand。您可以将触发器的 EventName 指定为 Loaded,然后在触发 Loaded 事件时执行您的命令(在虚拟机中定义)。

One way of doing it is to use InvokeDataCommand. You'd specify the trigger's EventName as Loaded, and then your command (defined in your VM) would execute when Loaded event is fired.

风启觞 2024-08-22 12:08:34

您需要研究命令。与 WPF 相比,Silverlight 支持相当弱,但它确实包含 ICommand 接口。您可以扩展控件以赋予它们命令属性或通过附加属性实现它们。一旦 UI 中发生操作,这些命令基本上就会调用自身。它们完全独立于 UI 的构建方式(或者至少应该如此),因此可以进行完全的单元测试。

You need to look into commanding. Silverlight support is fairly weak compared to WPF but it does contain the ICommand interface. You can extend controls to give them command properties or implement them via an attached property. The commands basically invoke themselves once an action has occurred in the UI. They are totally independent of how the UI is built (or at least they should be) and so can be completely unit tested.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文