Another way to do, without popups.
public class MapPanInsideScrollViewerBehavior : Behavior<Map>
{
#region overrides
protected override void OnAttached()
{
base.OnAttached();
this.AssociatedObject.MouseLeftButtonDown += AssociatedObject_MouseLeftButtonDown;
this.AssociatedObject.Loaded += AssociatedObject_Loaded;
}
protected override void OnDetaching()
{
base.OnDetaching();
this.AssociatedObject.MouseLeftButtonDown -= AssociatedObject_MouseLeftButtonDown;
DetachDispatchingEvent();
}
#endregion
#region callbacks
void AssociatedObject_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
}
void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
{
this.AssociatedObject.Loaded -= AssociatedObject_Loaded;
AttachDispatchingEvent();
}
void fw_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.Dispatcher.BeginInvoke(() => e.Handled = false);
}
#endregion
#region methods
void AttachDispatchingEvent()
{
FrameworkElement fw = this.AssociatedObject.FindDescended<FrameworkElement>();
fw.MouseLeftButtonDown += fw_MouseLeftButtonDown;
}
void DetachDispatchingEvent()
{
FrameworkElement fw = this.AssociatedObject.FindDescended<FrameworkElement>();
fw.MouseLeftButtonDown -= fw_MouseLeftButtonDown;
}
#endregion
}
create & add this behavior to the Map control, this will prevent from ScrollViewer to reclaim focus on it, which causing the Map to stop panning, and than return the RoutedEventArgs.Handled = false, which also can prevent from Map to pan.
!IMPORTANT!
inside the AttachDispatchingEvent and DetachDispatchingEvent methods, I'm using our internal helper method FindDescended on the AssociatedObject. its functionality is to find the first FrameworkElement inside the ControlTemplate of Map control. please replace it with your own implementation, cause it is not part of the attached code.
The reason for that use is, cause I needed to find a away to dispatch an action marking Handled=False before Map control dispatching its own action that checking if the routed event was handled by other control.