Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVVM interaction drop trigger

Tags:

mvvm

wpf

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

like image 496
John Avatar asked May 26 '26 10:05

John


2 Answers

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>
like image 161
Enrico Campidoglio Avatar answered Jun 01 '26 11:06

Enrico Campidoglio


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.

like image 45
Pongsathon.keng Avatar answered Jun 01 '26 10:06

Pongsathon.keng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!