Select to view content in your preferred language

Map and ScrollBar

1152
6
01-16-2012 02:45 AM
jonataspovoas
Regular Contributor
Hi,

In my project, I have a map that needs to be inside a ScrollBar. My problem is that when I do so, I lose the Pan functionality of the map. I really must find some way to make the pan work, and i also must give the user the possibility to scrolling possibility on the window (a ChildWindow) so it can see the whole content of the page.
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor
Look at this sample. There is a hack at the end of ScrollableMap.cs (without any guarantee though)
0 Kudos
jonataspovoas
Regular Contributor
Look at this sample. There is a hack at the end of ScrollableMap.cs (without any guarantee though)


The sample didn't open...
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The sample didn't open...

What do you mean? I just tested and I am able to view the live application and I am able to download the code and get the ScrollableMap.cs file.
0 Kudos
jonataspovoas
Regular Contributor
What do you mean? I just tested and I am able to view the live application and I am able to download the code and get the ScrollableMap.cs file.


Hi,

I managed to get the code (the proxy on my workplace was blocking the page), but I couldn't use the "hack" to assign the mouseLeftButtonDown/Up to the map. The path to my map is something like this:

I have my ScrollViwer, and inside of it a Grid. The Grid gets through code the UserControl I use to define the ScrollViwer's content. It has another Grid that holds a StackPanel, that has Border countaining a Grid that has the Map, and a Navigator.

<ScrollViewer Margin="0,8,8,8"
              BorderBrush="{x:Null}"
              HorizontalScrollBarVisibility="Auto" 
              VerticalScrollBarVisibility="Auto">
    <Grid x:Name="GridThatHoldsTheContent"/>
</ScrollViewer>

<!-- ... -->
<StackPanel Grid.Row="0" 
            MaxHeight="1454" 
            VerticalAlignment="Top" 
            Margin="25,25,28,0">
    <Border BorderThickness="1"
            BorderBrush="Black">
        <Grid>
            <esri:Map x:Name="Mapa"
                      VerticalAlignment="Top" 
                      WrapAround="True" 
                      Background="#FFC3D2E5" 
                      IsLogoVisible="False" 
                      Height="1187">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="ExtentChanged">
                        <i:InvokeCommandAction Command="{Binding AcaoExtentChanged}"
                                               CommandParameter="{Binding ElementName=Mapa}"/>
                        <ei:CallMethodAction MethodName="InvocaOMetodoDeHistoricosDoMapaNaViewModel" 
                                             TargetObject="{Binding ElementName=PaginaRetratoA3}"/>
                        <ei:CallMethodAction MethodName="ConfiguraExibicaoDeLegenda" 
                                             TargetObject="{Binding ElementName=PaginaRetratoA3}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </esri:Map>
            <esri:Navigation VerticalAlignment="Bottom" 
                             Margin="10,0,0,10" Background="#FF336397" 
                             Style="{StaticResource EstiloNavegadorImpressao}"
                             Map="{Binding ElementName=Mapa}"/>
        </Grid>
    </Border>
    <!-- ... -->
</StackPanel>


What should I do?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I got it working with this code:

public partial class TestScrollViewer : UserControl
{
    public TestScrollViewer()
    {
        InitializeComponent();
        MyMap.Loaded += AttachMouseLeftButtonHandlers; // maybe set in XAML as well : Loaded="AttachMouseLeftButtonHandlers"
    }
    private void AttachMouseLeftButtonHandlers(object sender, RoutedEventArgs e)
    {
        Map map = sender as Map;
        // Get the "RootElement" of the map   ~ of map.GetTemplateChild("RootElement") but GetTemplateChild is protected and Map is sealed
        var rootElement = ((FrameworkElement)VisualTreeHelper.GetChild(map, 0)).FindName("RootElement") as Grid;
        if (rootElement != null)
        {
            rootElement.MouseLeftButtonDown += RootElement_MouseLeftButtonDown;
            rootElement.MouseLeftButtonUp += (s, arg) => _upFired = true;
        }
    }
    // Hack to get the map taking care of the MouseLeftButtonDown event even if
    // this event is handled by the a parent element such as a scrollviewer
    private bool _upFired;
    void RootElement_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        _upFired = false;
        Dispatcher.BeginInvoke(() =>
                                {
                                    if (!_upFired) // else up event fired meanwhile 
                                        e.Handled = false;
                                });
    }
}


Reminder : code provided without any guarantee of good behavior for future versions or even for this version.
0 Kudos
jonataspovoas
Regular Contributor
Hi,

It worked!

Thanks a lot for your help!
0 Kudos