2013-04-01 30 views
3

我試圖獲取位置,當我點擊bing地圖控件時。我知道如何得到它,但我想在ViewModel中製作。對於Tap事件,我使用交互。從mvvm的Tap活動中獲取bing地圖的位置

<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> 

我可以通過GetPosition函數從eventarguments中獲取位置。不過這個功能需要的UIElement parameter.I作出如此:

var source = (e.OriginalSource as MapLayer).ParentMap; 
     var point = e.GetPosition(source); 
     Location = source.ViewportPointToLocation(point); 

但林不知道,如果它是很好的解決方案。你有什麼想法如何做到這一點? 謝謝

回答

2

那麼,你的方法當然有效,有時候,夠好夠好。 ;)如果你想用你的MVVM實現100%乾淨,你應該避免引用視圖(也就是MapLayer類)。

Joost的麪包車範斯海克寫了一篇博客文章,說明如何實現這一使用行爲(這是針對Windows Phone 8的,但我敢肯定它適用於Windows Phone 7的爲好):http://dotnetbyexample.blogspot.nl/2013/03/simple-reverse-geocoding-with-windows.html

+0

由於這是我neeed。 – Pupino

相關問題