Are there any plans to get this to work? Or is there a work around?
<!-- Xaml - button that activates the "pan" --> <Button Style="{StaticResource MenuButtonStyle}" Click="BtnPan_click" Width="40" Height="35" Margin="5"> <Image Source="Images/target.png" /> </Button>
string _toolMode = ""; private Draw pointToPan; private void BtnPan_click(object sender, RoutedEventArgs e) { pointToPan.IsEnabled = true; _toolMode = "Pan"; } public LayoutDeImpressao() { pointToPan = new Draw(targetedMap) { FillSymbol = DefaultFillSymbol, DrawMode = DrawMode.Point }; pointToPan.DrawComplete += PointToPan_DrawComplete; } private void PointToPan_DrawComplete(object sender, DrawEventArgs args) { if (_toolMode == "Pan") { targetedMap.PanTo(args.Geometry as ESRI.ArcGIS.Client.Geometry.MapPoint); } }
I know this post is old,
but it seems, that even in the new releases, the silverlight control doesn't support panning inside ScrollViewer.
as our app must be all wrapped inside a scroll viewer, we have found an elegant workaround.
Just put the Esri Map control inside a Popup, and the popup make a child of the ScrollViewer, with IsOpen="True"
then make sure to define the desired Size for the Map control (cause the popup always adjust its size to the child size, and that not good for us), and walla, it's working like a charm.
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.