gpt4 book ai didi

mvvm - Prism/mvvm : how to bind GotFocus of View to an action?

转载 作者:行者123 更新时间:2023-12-03 10:40:27 24 4
gpt4 key购买 nike

我有一个 prism/mvvm View ,如果 View 获得或失去焦点,我想通知 ViewModel。

我想我需要将 View 的 GotFocus 绑定(bind)到 ViewModel 中的一个 Action ,但我不知道如何开始。

当然这是一个已经在某个地方解决的标准问题,只是我没有找到解决方案?

最佳答案

您可以使用 InvokeCommandAction行为。此行为在作为 Expression Blend 一部分的程序集 System.Windows.Interactivity 中定义。通过这种行为,您可以绑定(bind)到 View 的 GotFocus 事件并在 View 模型中执行命令。

您可以对 LostFocus 使用相同的方法。 Here是如何使用 InvokeCommandAction 的示例。

关于 UserControl 的 GotFocus 的一件事。您应该知道当控件(例如 TextBox)获得焦点时会引发 View 的 GotFocus 事件。您不能单独关注 UserControl。

[更新]
当 IsTabStop 设置为 true 时,会引发 UserControl 的 GotFocus

你不能使用 IActiveAware Prism 框架的接口(interface)。当 View 在区域中导航时,将设置 IsActive 属性。

该接口(interface)可以在 View 上实现,并且 ViewModel(需要将 viewmodel 实例设置为 View 的 DataContext)在该区域中激活 View 时得到通知。

关于mvvm - Prism/mvvm : how to bind GotFocus of View to an action?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5077025/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com