Silverlight 如何设置可拖动图钉的动画
我正在寻找一种方法来显示图钉在地图上被拖动的运动。 我试图修改此处提出的一个示例: 通过更新添加到MouseMove事件处理程序的委托中的AssociatedObject.Location,但这不会产生任何结果。在松开鼠标按钮之前,图钉一直保持在原来的位置。然后它跳到新的位置Silverlight 如何设置可拖动图钉的动画,silverlight,bing-maps,pushpin,Silverlight,Bing Maps,Pushpin,我正在寻找一种方法来显示图钉在地图上被拖动的运动。 我试图修改此处提出的一个示例: 通过更新添加到MouseMove事件处理程序的委托中的AssociatedObject.Location,但这不会产生任何结果。在松开鼠标按钮之前,图钉一直保持在原来的位置。然后它跳到新的位置 知道如何在拖动过程中强制MapLayer跟踪图钉位置,并在鼠标移动时正确地重新绘制图钉位置吗?Max,你能说明你想做什么吗?这里的方法听起来很合理,但每次鼠标移动时让地图重新计算pin的位置有点不必要。像这样的怎么样 当p
知道如何在拖动过程中强制MapLayer跟踪图钉位置,并在鼠标移动时正确地重新绘制图钉位置吗?Max,你能说明你想做什么吗?这里的方法听起来很合理,但每次鼠标移动时让地图重新计算pin的位置有点不必要。像这样的怎么样
麦克斯,你能澄清一下你想做什么吗?这里的方法听起来很合理,但每次鼠标移动时让地图重新计算pin的位置有点不必要。像这样的怎么样
我在制定自己的解决方案时遇到了这个问题,我很高兴看到它完全按照您描述的那样工作,我想我会发布它。要注意的是,我还使用了一个双向MVVM绑定模式,它可以完美地工作。你需要两件事: 1) 此扩展方法有助于在运行时查找作为pin父对象的MapLayer:
public static T FindVisualParent<T>(this DependencyObject obj)
where T : DependencyObject
{
DependencyObject parent = VisualTreeHelper.GetParent(obj);
while (parent != null)
{
T typed = parent as T;
if (typed != null)
{
return typed;
}
parent = VisualTreeHelper.GetParent(parent);
}
return null;
}
public static T FindVisualParent(此DependencyObject obj)
其中T:DependencyObject
{
DependencyObject parent=VisualTreeHelper.GetParent(obj);
while(父级!=null)
{
T类型=作为T的父级;
如果(已键入!=null)
{
返回类型;
}
父级=VisualTreeHelper.GetParent(父级);
}
返回null;
}
2) 在图钉上的拖动事件处理程序中,调用该扩展方法以引用宿主MapLayer,然后触发最漂亮的InvalidateArrange方法(来自UIElement),如下所示:
void ParentMap_MouseMove(object sender, MouseEventArgs e)
{
var map = sender as Microsoft.Maps.MapControl.Map;
var parentLayer = this.FindVisualParent<MapLayer>();
if (this.isDragging)
{
var mouseMapPosition = e.GetPosition(map);
var mouseGeocode = map.ViewportPointToLocation(mouseMapPosition);
this.Location = mouseGeocode;
parentLayer.InvalidateArrange();
}
}
void ParentMap\u MouseMove(对象发送方,MouseEventArgs e)
{
var map=发送方为Microsoft.Maps.MapControl.map;
var parentLayer=this.FindVisualParent();
如果(这是我的错)
{
var mouseMapPosition=e.GetPosition(map);
var mouseGeocode=map.ViewportPointToLocation(mouseMaposition);
this.Location=mouseGeocode;
parentLayer.InvalidateArrange();
}
}
这将异步执行可视化更新,并在销拖动时为您提供良好的滑动行为。HTH我在制定自己的解决方案时遇到了这个问题,我很高兴看到它完全按照您的描述工作,我想我会发布它。要注意的是,我还使用了一个双向MVVM绑定模式,它可以完美地工作。你需要两件事: 1) 此扩展方法有助于在运行时查找作为pin父对象的MapLayer:
public static T FindVisualParent<T>(this DependencyObject obj)
where T : DependencyObject
{
DependencyObject parent = VisualTreeHelper.GetParent(obj);
while (parent != null)
{
T typed = parent as T;
if (typed != null)
{
return typed;
}
parent = VisualTreeHelper.GetParent(parent);
}
return null;
}
public static T FindVisualParent(此DependencyObject obj)
其中T:DependencyObject
{
DependencyObject parent=VisualTreeHelper.GetParent(obj);
while(父级!=null)
{
T类型=作为T的父级;
如果(已键入!=null)
{
返回类型;
}
父级=VisualTreeHelper.GetParent(父级);
}
返回null;
}
2) 在图钉上的拖动事件处理程序中,调用该扩展方法以引用宿主MapLayer,然后触发最漂亮的InvalidateArrange方法(来自UIElement),如下所示:
void ParentMap_MouseMove(object sender, MouseEventArgs e)
{
var map = sender as Microsoft.Maps.MapControl.Map;
var parentLayer = this.FindVisualParent<MapLayer>();
if (this.isDragging)
{
var mouseMapPosition = e.GetPosition(map);
var mouseGeocode = map.ViewportPointToLocation(mouseMapPosition);
this.Location = mouseGeocode;
parentLayer.InvalidateArrange();
}
}
void ParentMap\u MouseMove(对象发送方,MouseEventArgs e)
{
var map=发送方为Microsoft.Maps.MapControl.map;
var parentLayer=this.FindVisualParent();
如果(这是我的错)
{
var mouseMapPosition=e.GetPosition(map);
var mouseGeocode=map.ViewportPointToLocation(mouseMaposition);
this.Location=mouseGeocode;
parentLayer.InvalidateArrange();
}
}
这将异步执行可视化更新,并在销拖动时为您提供良好的滑动行为。HTH在Silverlight工具包中,WP7通过GestureListener提供了一个随时可用的解决方案:
<my:Pushpin Location="{Binding Location}">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted"/>
</toolkit:GestureService.GestureListener>
</my:Pushpin>
private void GestureListener_DragStarted(object sender, DragStartedGestureEventArgs e)
{
Map.IsEnabled = false;
}
private void GestureListener_DragCompleted(object sender, DragCompletedGestureEventArgs e)
{
Map.IsEnabled = true;
}
private void GestureListener_DragDelta(object sender, DragDeltaGestureEventArgs e)
{
Point p = e.GetPosition(Map);
App.ViewModel.Location = Map.ViewportPointToLocation(p);
}
私有void GestureListener_DragStarted(对象发送方,DragStartedTestureEventArgs e)
{
Map.IsEnabled=false;
}
私有void GestureListener_DragCompleted(对象发送方,DragCompletedGestureEventArgs e)
{
Map.IsEnabled=true;
}
私有void GestureListener_DragDelta(对象发送方,DragDeltaGestureEventArgs e)
{
点p=e.GetPosition(地图);
App.ViewModel.Location=Map.ViewportPointToLocation(p);
}
通过GestureListener,Silverlight WP7工具包中有一个现成的解决方案:
<my:Pushpin Location="{Binding Location}">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted"/>
</toolkit:GestureService.GestureListener>
</my:Pushpin>
private void GestureListener_DragStarted(object sender, DragStartedGestureEventArgs e)
{
Map.IsEnabled = false;
}
private void GestureListener_DragCompleted(object sender, DragCompletedGestureEventArgs e)
{
Map.IsEnabled = true;
}
private void GestureListener_DragDelta(object sender, DragDeltaGestureEventArgs e)
{
Point p = e.GetPosition(Map);
App.ViewModel.Location = Map.ViewportPointToLocation(p);
}
私有void GestureListener_DragStarted(对象发送方,DragStartedTestureEventArgs e)
{
Map.IsEnabled=false;
}
私有void GestureListener_DragCompleted(对象发送方,DragCompletedGestureEventArgs e)
{
Map.IsEnabled=true;
}
私有void GestureListener_DragDelta(对象发送方,DragDeltaGestureEventArgs e)
{
点p=e.GetPosition(地图);
App.ViewModel.Location=Map.ViewportPointToLocation(p);
}
当我在硬编码到XAML中的图钉上使用相同的行为时,该方法的工作原理与