w33z33
w33z33

Reputation: 378

WPF Bingmaps pushpin event binding mvvm

I would like to trigger a command in my ViewModel when the pushpin is clicked on the map. How can I achieve this using databinding?

Here is the DataTemplate I am using for the pinpoints:

<DataTemplate x:Key="PushPinTemplate">
    <map:Pushpin Cursor="Hand"
                 map:MapLayer.Position="{Binding Location}">
    </map:Pushpin>
</DataTemplate>

Upvotes: 0

Views: 863

Answers (1)

w33z33
w33z33

Reputation: 378

A colleague found the solution:

After adding the Nuget Package System.Windows.Interactivity.WPF and adding the xml namespace

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

you can add an EventTrigger to the template, here the full template code, where CachePushPinClicked is an ICommand

<DataTemplate x:Key="PushPinTemplate">
    <map:Pushpin Cursor="Hand"
                     map:MapLayer.Position="{Binding Location}" >   
     <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeftButtonDown">
            <i:InvokeCommandAction Command="{Binding CachePushPinClicked}"/>
        </i:EventTrigger>
     </i:Interaction.Triggers>
   </map:Pushpin>
</DataTemplate>

Upvotes: 2

Related Questions