2011-02-01 112 views
1

我有一個地圖控件,顯示一些圖釘。我不希望用戶在地圖中導航,所以我禁用它。但我確實希望用戶能夠點按圖釘(並且在導航到詳細信息頁面的情況下)。在固定地圖上使用圖釘處理水龍頭

但是,當Map.IsEnabled爲false時,Pushpins似乎也不會接收任何手勢。我也嘗試使用IsHitTestVisible,但沒有運氣。

一些代碼顯示我正在嘗試做什麼。有沒有人有任何想法?

<maps:Map Name="Map" 
      VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
      CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" ScaleVisibility="Collapsed" ZoomBarVisibility="Collapsed" 
      IsEnabled="False"> 
    <maps:MapItemsControl ItemsSource="{Binding TheCollection}"> 
     <maps:MapItemsControl.ItemTemplate> 
      <DataTemplate> 
       <maps:Pushpin Name="Pin" Location="{Binding Coordinate}" Content="{Binding Ix}"> 
        <maps:Pushpin.Background> 
         <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/> 
        </maps:Pushpin.Background> 

        <toolkit:GestureService.GestureListener> 
         <toolkit:GestureListener Tap="PinTap" /> 
        </toolkit:GestureService.GestureListener> 
       </maps:Pushpin> 
      </DataTemplate> 
     </maps:MapItemsControl.ItemTemplate> 
    </maps:MapItemsControl> 
</maps:Map> 

回答

1

設置IsEnabledfalse防止響應用戶輸入,這會影響孩子Pushpin,你見過Map控制。如果您希望地圖是隻讀的,但Pushpin到再到手勢迴應,我認爲你有兩個選擇:

  1. 上的手柄Map控制所有的手勢事件,並設置e.Handledtrue,這將阻止Map本身無法處理事件,但應該讓PushPin免費處理輕按手勢。
  2. 創建的MapWriteableBitmap和顯示,而不是,然後顯示在頂部Pushpin(注:我懷疑是Pushpin控制不會對Map控制之外的工作,所以你需要創建/重模板控件看起來像一個Pushpin)。

UPDATE:你需要處理的Map事件使其出現「只讀」,但仍然啓用是MapPanMapZoom

+0

我會試試看。而且,是的,圖釘在地圖之外工作。我將它用在隨附的ListBox中,以便在列表和地圖中具有相同的「外觀」項目。 – Ostemar 2011-02-01 16:10:21

+0

關於如何實現「處理所有手勢事件」的任何想法。我已經處理了操作[已啓動,增量,已完成]和MouseLeftButton [向下,向上]並將e.Handled設置爲true。那些沒有幫助。還有什麼我應該做的? – Ostemar 2011-02-01 16:41:52

1

所以這裏是我經過大量測試和瀏覽MSDN後解決的。事實證明,Windows Phone上的地圖控件有點不同(參見MSDN)。與普通的Silverlight相比,有新的行爲和事件。

<maps:Map Name="Map" 
      VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
      CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" ScaleVisibility="Collapsed" ZoomBarVisibility="Collapsed" 
      MapZoom="Map_MapZoom" MapPan="Map_MapPan"> 
    <maps:MapItemsControl ItemsSource="{Binding TheCollection}"> 
     <maps:MapItemsControl.ItemTemplate> 
      <DataTemplate> 
       <maps:Pushpin Name="Pin" Location="{Binding Coordinate}" Content="{Binding Ix}"> 
        <maps:Pushpin.Background> 
         <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/> 
        </maps:Pushpin.Background> 

        <toolkit:GestureService.GestureListener> 
         <toolkit:GestureListener Tap="PinTap" /> 
        </toolkit:GestureService.GestureListener> 
       </maps:Pushpin> 
      </DataTemplate> 
     </maps:MapItemsControl.ItemTemplate> 
    </maps:MapItemsControl> 
</maps:Map> 

... 

private void Map_MapPan(object sender, MapDragEventArgs e) 
{ 
    e.Handled = true; 
} 

private void Map_MapZoom(object sender, MapZoomEventArgs e) 
{ 
    e.Handled = true; 
}