我正在努力使GMap.Net http://greatmaps.codeplex.com/使用 WPF 内置事件控制启用多点触控,但我没有成功。
我发现了一系列关于多点触控的文章,例如this http://blogs.msdn.com/b/jaimer/archive/2009/11/04/introduction-to-wpf-4-multitouch.aspx and this http://blogs.msdn.com/b/ansont/archive/2010/01/11/multi-touch-in-wpf-4-part-3-manipulation-events.aspx一。在所有这些中,ManipulationContainer
是一个画布和放置在其上的可移动控件,但在 GMap 问题中ManipulationContainer
is GMapControl
并且无法控制它。我该如何使用e.ManipulationDelta
数据缩放和移动?
The GMapControl
has a Zoom
属性,通过增加或减少它,您可以放大或缩小。
快速浏览一下代码就会发现GMapControl is an ItemsContainer http://greatmaps.codeplex.com/SourceControl/changeset/view/f3ac356fa16e#GMap.NET.WindowsPresentation%2fGMap.NET.WindowsPresentation%2fGMapControl.cs.
您应该能够重新设计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 演练 http://msdn.microsoft.com/en-us/library/ee649090.aspx):
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)