Select to view content in your preferred language

Drag and Drop onto Map

2452
13
Jump to solution
01-22-2014 11:23 AM
Labels (1)
KeithGemeinhart
Regular Contributor
I'm looking for advice on implementing drag & drop onto the WPF map control. My goal is to drag from a list of items, and drop on the map to create a new graphic/feature at the drop location.

The map has Drop and PreviewDrop events, but neither provide the map/mouse coordinates of the drop event. Am I missing something in the events? Both have DragEventArgs as the parameter.

All I really need is the mouse's map position when the drop happens. With that in mind, I also tried to get mouse move events, but they don't seem to carry any position either, only MouseEventArgs.

Any ideas? Am I missing something obvious?

Thanks!

P.S. ArcGIS Runtime 10.1.1, but I can upgrade to 10.2 if there is something that will help.
0 Kudos
13 Replies
AnttiKajanus1
Deactivated User
I have this wired-up using a Command & ViewModel. I can post that part if anyone is interested, just let me know.


Oh, that would awesome. But guess what would be even more, small complete sample with MVVM and Drag'n'drop :cool:.
0 Kudos
KeithGemeinhart
Regular Contributor
I will put together a sample and post it soon.

Oh, that would awesome. But guess what would be even more, small complete sample with MVVM and Drag'n'drop :cool:.
0 Kudos
KeithGemeinhart
Regular Contributor
Here is a sample project that you download: https://github.com/keithgemeinhart/ArcGis.Wpf.DragDropDemo

A couple of key points ....

I use the GalaSoft MVVM Light library to get an implementation of EventToCommand. The provides a mechanism for mapping an event to a command in the view model. For example:

<i:Interaction.Triggers >    <i:EventTrigger EventName="Loaded">     <cmd:EventToCommand Command="{Binding MapLoadedCommand, Source={StaticResource DragDropViewModel}}" PassEventArgsToCommand="True"/>    </i:EventTrigger> </i:Interaction.Triggers>


This maps the Loaded event on the map to the MapLoadedCommand in the DragDropViewModel. That's a key event because we need a means for getting a map reference into the view model. So my solution was to capture the map reference as a parameter of the map's Loaded event. Here is the implementation in the view model. The last line in the method extracts the map reference from the RoutedEventArgs Source property.

private void MapLoaded(object parameter) {     // See if the event sent the map in the event args     var p1 = parameter as System.Windows.RoutedEventArgs;     if (p1 == null)     {         throw new NullReferenceException("Cannot capture map reference.");         return;     }      _map = p1.Source as Map; }


If you have any questions, just let me know.
0 Kudos
AnttiKajanus1
Deactivated User
Good sample Keith.

More of these guys!
0 Kudos