Map clicking doesn't work as expected

3 posts, 1 answers
  1. liviu
    liviu avatar
    2 posts
    Member since:
    Feb 2011

    Posted 08 Feb 2011 Link to this post

    Hi, I display some pushpins on the map, and when I "LeftMouseButtonDown" on either of them I show a popup.
    I have the following code:     

    <telerik:RadMap x:Name="radMap" Grid.Row="0" ZoomLevel="1" DistanceUnit="Kilometer" MouseClickMode="None" InitializeCompleted="radMap_InitializeCompleted">
        <telerik:InformationLayer x:Name="informationLayer">
            <telerik:InformationLayer.ItemTemplate>
                <DataTemplate>
                    <Grid telerik:MapLayer.Location="{Binding Location}" MinWidth="250" MaxWidth="600" Height="100" Background="Transparent" MouseLeftButtonDown="Grid_MouseLeftButtonDown" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                         
                         
                        <telerik:Pushpin Grid.Row="1" HorizontalAlignment="Center" MouseLeftButtonDown="Pushpin_MouseLeftButtonDown"/>
                    </Grid>
                </DataTemplate>
            </telerik:InformationLayer.ItemTemplate>
        </telerik:InformationLayer>
    </telerik:RadMap>

    Code behind is:
    public MainPage()
    {
        InitializeComponent();
        this.radMap.Provider = new BingMapProvider(MapMode.Road, true, "key");
        ClosePopup.Click += new RoutedEventHandler(ClosePopup_Click);
    }
     
    void ClosePopup_Click(object sender, RoutedEventArgs e)
    {
        MyPopup.IsOpen = false;
    }
     
     
    private ObservableCollection<MapItem> GetMapData()
    {
        ObservableCollection<MapItem> data = new ObservableCollection<MapItem>();
        data.Add(new MapItem("Sofia", new Location(42.6957539183824, 23.3327663758679), 5, new ZoomRange(5, 12)));
        data.Add(new MapItem("Plovdiv", new Location(80.1429369264591, 24.7498095849434), 5, new ZoomRange(5, 12)));
        data.Add(new MapItem("Burgas", new Location(12.5131732087098, 27.4611884843576), 5, new ZoomRange(5, 12)));
        data.Add(new MapItem("Varna", new Location(80.2073941930888, 90.9275176988258), 5, new ZoomRange(5, 12)));
        data.Add(new MapItem("Varna", new Location(120.2073941930888, 10.9275176988258), 5, new ZoomRange(5, 12)));
        data.Add(new MapItem("Varna", new Location(1.2073941930888, 12.9275176988258), 5, new ZoomRange(5, 12)));
        data.Add(new MapItem("Sofia", new Location(42.6957539183824, 73.3327663758679), 5, new ZoomRange(5, 12)));
        data.Add(new MapItem("Sofia", new Location(100.6957539183824, 115.3327663758679), 5, new ZoomRange(5, 12)));
        data.Add(new MapItem("Sofia", new Location(100.6957539183824, 1.3327663758679), 5, new ZoomRange(5, 12)));
        return data;
    }
     
    private void Pushpin_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        MyPopup.IsOpen = true;
    }
     
    private void radMap_InitializeCompleted(object sender, EventArgs e)
    {
        this.informationLayer.ItemsSource = GetMapData();
    }
     
    private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        //MyPopup.IsOpen = true;
    }


    The problem is that the "Pushpin_MouseLeftButtonDown" doesn't always get called. Sometimes it does, sometimes it doesn't.
    I did notice thought that the "Grid_MouseLeftButtonDown" always gets called, but that doesn't help because I really need to have "Pushpin_MouseLeftButtonDown" always called.

    Do you know how I could achieve this?
  2. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 10 Feb 2011 Link to this post

    Hello liviu,

    This is the expected behavior for events handling in Silverlight. You set the transparent to background of the Grid element. So, it handles mouse events. When the grid overlaps another with its pushpin then the pushpin cannot handle mouse events.
    You can just remove the background of the grid. In this case pushpins will get mouse event as expected.

    All the best,
    Andrey Murzov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
  4. liviu
    liviu avatar
    2 posts
    Member since:
    Feb 2011

    Posted 11 Feb 2011 Link to this post

    The problem is now fixed.
    Many thanks for helping me with the answer, Andrey.
Back to Top