i'm trying to get location, when I tap on bing map control. I know how to get it, but I want to make it in ViewModel. For Tap event I use interactions.
<map:Map CopyrightVisibility="Collapsed" LogoVisibility="Collapsed">
<map:MapTileLayer>
<map:MapTileLayer.TileSources>
<customMap:OpenStreetTile />
</map:MapTileLayer.TileSources>
</map:MapTileLayer>
<map:MapLayer>
<map:Pushpin Location="{Binding Location}" />
</map:MapLayer>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<cmd:EventToCommand Command="{Binding AddPushpinCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</map:Map>
I can get position from eventarguments with GetPosition function. But this function need UIElement parameter.I made it so:
var source = (e.OriginalSource as MapLayer).ParentMap;
var point = e.GetPosition(source);
Location = source.ViewportPointToLocation(point);
But Im not sure if it is good solution. Do you have any idea how to do it? Thanks
Well, your approach certainly works and sometimes, good enough is good enough. ;) If you want to be 100% clean with your MVVM implementation, you should avoid references to the view (and thus the MapLayer class) however.
Joost van Schaik wrote a blog post that shows how to achieve this using behaviors (it's for Windows Phone 8, but I'm sure it applies to Windows Phone 7 as well): http://dotnetbyexample.blogspot.nl/2013/03/simple-reverse-geocoding-with-windows.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With