这是当前的实现正在做的事情:
在OnMouseWheel 中调用如下方法:
this.ZoomAboutViewportPoint(((double) e.Delta) / 100.0, e.GetPosition(this));
它的实现是:
private void ZoomAboutViewportPoint(double zoomLevelIncrement, Point zoomTargetInViewport)
{
base.ZoomAndRotateOrigin = new Point?(zoomTargetInViewport);
base.ViewBeingSetByUserInput = true;
base.SetView((double) (base.TargetZoomLevel + zoomLevelIncrement), base.TargetHeading);
base.ViewBeingSetByUserInput = false;
}
显然你不能直接设置base.ViewBeingSetByUserInput 和base.ZoomAndRotateOrigin,因为它们是内部的。
但是,您可以将SetView 与视口坐标相应地使用,但仍会丢失漂亮的动画部分。
或者,您可以通过反射设置上述值,但这是一个脆弱的 hack,如果控制发生变化,很容易中断。
--- 更新
如上所述:如果您连接到MouseWheel 事件,这里是通过私有方法的反射调用使其工作的代码:
void BingMap_MouseWheel(object sender, MouseWheelEventArgs e)
{
e.Handled = true;
System.Reflection.MethodInfo dynMethod = this.BingMap.GetType().GetMethod("ZoomAboutViewportPoint", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
dynMethod.Invoke(this.BingMap, new object[] { (((double)e.Delta) / 400d), e.GetPosition(this.BingMap) });
}
这使它的速度降低了四分之一,并使其可以用最少的代码使用。但这又是一个 hack!