2012-02-29 193 views
3

我試圖讓GMap.Net控制多點觸控啓用,使用WPF內置事件,但我沒有成功。縮放和平移在GMap.net

我發現了一系列有關多點觸控的文章,如thisthis之一。在所有這些中,ManipulationContainer是放置在其上的畫布和可移動控件,但是在GMap問題ManipulationContainer中是GMapControl,並且不能控制它。我如何使用e.ManipulationDelta數據進行縮放和移動?

GMapControl有一個Zoom財產,通過增加或減少它,你可以放大或縮小。

回答

3

快速查看代碼顯示GMapControl is an ItemsContainer

你應該能夠再整的ItemsPanel模板並提供IsManipulationEnabled屬性有:

<g:GMapControl x:Name="Map" ...> 
    <g:GMapControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <Canvas IsManipulationEnabled="True" /> 
     </ItemsPanelTemplate> 
    </g:GMapControl.ItemsPanel> 
    <!-- ... --> 

在這一點上,你需要的電纜鋪設Window

<Window ... 
    ManipulationStarting="Window_ManipulationStarting" 
    ManipulationDelta="Window_ManipulationDelta" 
    ManipulationInertiaStarting="Window_InertiaStarting"> 

,並提供適當的方法在代碼後面(無恥地從這個MSDN Walkthrough中偷竊和改編):

void Window_ManipulationStarting(
    object sender, ManipulationStartingEventArgs e) 
{ 
    e.ManipulationContainer = this; 
    e.Handled = true; 
} 

void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) 
{ 
    // uses the scaling value to supply the Zoom amount 
    this.Map.Zoom = e.DeltaManipulation.Scale.X; 
    e.Handled = true; 
} 

void Window_InertiaStarting(
    object sender, ManipulationInertiaStartingEventArgs e) 
{ 
    // Decrease the velocity of the Rectangle's resizing by 
    // 0.1 inches per second every second. 
    // (0.1 inches * 96 pixels per inch/(1000ms^2) 
    e.ExpansionBehavior.DesiredDeceleration = 0.1 * 96/(1000.0 * 1000.0); 
    e.Handled = true; 
}