3

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

John
  • 1,403
  • 3
  • 19
  • 31

2 Answers2

3

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>
Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
  • 1
    Thanks for that. While investigating I also found this [link](http://weblogs.asp.net/alexeyzakharov/archive/2010/03/24/silverlight-commands-hacks-passing-eventargs-as-commandparameter-to-delegatecommand-triggered-by-eventtrigger.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+AlexeyZakharov+(Alexey+Zakharovs+Blog)) – John Feb 16 '12 at 09:15
2

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.

Community
  • 1
  • 1
Pongsathon.keng
  • 1,417
  • 11
  • 14