gpt4 book ai didi

c# - 在 Prism 中处理 PreviewMouseDown 和 PreviewMouseUp 事件

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

我有一个 Prism 应用程序,我正在尝试将 View 中的 PreviewMouseDown 和 PreviewMouseUp 按钮事件绑定(bind)到 View 模型中的命令。当我运行代码时,我看到以下异常:
enter image description here
作为一种解决方法,我目前正在绑定(bind)到 View 中的方法,并使用对 View 模型的数据上下文的引用来执行命令。这可行但似乎不正确,因为 View 现在具有 View 模型的知识。
处理这样的事情的正确方法是什么?

最佳答案

您不能将事件绑定(bind)到命令,例如 Command按钮的属性。
幸运的是,您不需要这样做,因为您拥有 Command属性(property)。如果命令返回 false,它甚至会禁用按钮。来自 CanExecute .
如果您有按钮以外的东西或 MouseDown 以外的东西, 你可以使用 InvokeCommandAction (来自 Prism 或来自 Interactivity)...

xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<prism:InvokeCommandAction Command="{Binding MyCommand}"/>
<!-- or -->
<i:InvokeCommandAction Command="{Binding MyCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>

关于c# - 在 Prism 中处理 PreviewMouseDown 和 PreviewMouseUp 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65309047/

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