MVVM交互丢弃触发

发布于 2025-01-06 21:19:24 字数 487 浏览 1 评论 0 原文

我有一个 ListView,我需要将其用作放置目标。我添加了以下触发器

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Drop">
        <i:InvokeCommandAction Command="{Binding ItemsDroppedCommand}" 
            CommandParameter="{Binding ???}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

问题是虽然我不知道如何获取掉落的物品。 CommandParameter 绑定中应该包含哪些内容?

如果我在后面的代码中执行放置处理程序,我会得到一个 DragEventArgs 参数,该参数使我能够放置文件。有办法得到这个吗?

如果这是错误的方法,请随时提出替代方案

I have a ListView that I need to function as a drop target. I have added the following trigger

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Drop">
        <i:InvokeCommandAction Command="{Binding ItemsDroppedCommand}" 
            CommandParameter="{Binding ???}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

The problem is though I dont know how to get the dropped items. What should go in the CommandParameter binding?

If I do a drop handler in code behind I get a DragEventArgs parameter that enables me to get the files dropped. Is there a way to get this?

If this is the wrong approach please feel free to suggest alternatives

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

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

发布评论

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

评论(2

メ斷腸人バ 2025-01-13 21:19:24

不支持开箱即用地通过绑定将事件参数传递给命令,但可以通过解决方法

但是,我建议您使用 MVVM 中提供了 rel="nofollow">EventToCommand 行为Light,它恰好实现了这种场景:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Drop">
        <cmd:EventToCommand Command="{Binding ItemsDroppedCommand}"
                            PassEventArgsToCommand="True" />
    </i:EventTrigger>
</i:Interaction.Triggers>

Passing an event's arguments to a Command through binding isn't supported out of the box but can be achieved through a workaround.

However, I would recommend you to use the EventToCommand behavior available in MVVM Light, which enables exactly this scenario:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Drop">
        <cmd:EventToCommand Command="{Binding ItemsDroppedCommand}"
                            PassEventArgsToCommand="True" />
    </i:EventTrigger>
</i:Interaction.Triggers>
东走西顾 2025-01-13 21:19:24

请查看此线程 MVVM Passing EventArgs As Command Parameter

在此线程中将帮助您解决问题。
我希望这有帮助。

please take a look on this thread MVVM Passing EventArgs As Command Parameter

In this thread will help you solve the problem.
I hope this help.

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