When MapControl placed inside ScrollViewer pan not working

05-15-2012 04:30 AM
Labels (1)
New Contributor

When i place the map control inside a ScrollViewer the pan is not working (i still receive MouseMove and the zoom by mouse wheel still working as well as the esri:Navigation, esri:OverviewMap etc..)

You can recreate this issue with the following code:

<Window x:Class="TestMapScrollViewerIssue.MainWindow"
        Title="MainWindow" Height="350" Width="525">

        <ScrollViewer VerticalScrollBarVisibility="Auto"

            <!-- Map Control-->
            <esri:Map x:Name="_mapControl"

                <!-- * Tiled Basemap Layer(s) * -->

                <!-- ArcGIS Online Tiled Basemap Layer -->
                <esri:ArcGISTiledMapServiceLayer ID="arcGISTiledMapServiceLayer"
                                                 Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />

Please let me know if i am doing something wrong.

0 Kudos
7 Replies
Esri Regular Contributor
This is known issue with the ScrollViewer. The ScrollViewer intercepts the mouse event and marks it Handled=True, so the map control cannot pan/zoom.
There seems to be a workaround as suggested in this forum thread: http://forums.arcgis.com/threads/46519-ScrollViewer-Prevents-Panning
0 Kudos
New Contributor
Jennifer hi,

Thanks for the link.
I've implemented the panning and I am able to perform panning, however the behavior is not as smooth as in the regular pan operation (performed by the Esri map control) and it is a little bit erratic.
Is there a recommended implementation for pan?

0 Kudos
Esri Regular Contributor
I think recommended way is to not use ScrollViewer or control (i.e. ListBox, Accordion, etc) that will intercept the mouse events. I actually have not tried the workaround so I don't know how efficient it is.
0 Kudos
New Contributor
I have no control on whether there is a ScrollViewer in the visual tree or not because i provide a UserControl that wraps the MapControl and developers from other modules can add the control.
Sometimes they place it in a wizard like window that includes a scrollviewer and sometimes there is no scrollviewer.

I currently check in the loaded event of my wrapper if i have an ancestor of type ScrollViewer in the visual tree and only then i implemented the custom panning.

Other Wpf map controls have no issues in panning while inside scrollviewer (I suspect it is related to mouse capture issues)
0 Kudos
Occasional Contributor III
Perhaps you could also consider getting the sourcecode of the scrollviewer using reflector and implement your own scrollviewer that doesn't do IsHandled=true.
0 Kudos
Occasional Contributor II
Is this something ESRI plans on fixing in the next release?  Can someone for ESRI look into it and respond.

0 Kudos
Occasional Contributor
I also ran into this issue when working with a third party component that also set e.Handlet = true. Was able to override that behavior by extending the class that did this. However, it seems to me that the logic of Map is flawed. Where it should override OnMouseLeftButtonDown, it subscribes to the event. In that case, it doesn't follow the natural flow of overriding this event. A suggested fix for this issue would be to pass in the e.Handled when dispatching the delegate for performing the logic.

There are probably reasons why the design is as it is, but is this something that will be fixed? I am yet on version 2.x of the control, so I have not been able to verify if it has been resolved in 10.1.
0 Kudos