This is a migrated thread and some comments may be shown as answers.

Prevent RadMap from receiving handled double click event

4 Answers 155 Views
Map
This is a migrated thread and some comments may be shown as answers.
Etienne
Top achievements
Rank 1
Etienne asked on 24 Aug 2015, 06:45 PM

Hi,

Is it possible to not receive handled MouseDoubleClickEvent and MapMouseDoubleClickEvent in RadMap when the event is handled in a item of a map layer ? I've joined a sample that demonstrates the problematic behavior (for me).

Thank you,

Etienne

4 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 27 Aug 2015, 08:00 AM
Hi Etienne,

Since of the complex template structure of the map the handling MouseDoubleClick of the Pushpin won't affect the MouseDoubleClick event of the map as you may expect. In order to achieve your requirement you can use a bool flag in the event handlers. Here is an example in code:
private bool isMapDoubleClickHandled = false;
private void pushpin_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    var pushpin = sender as Pushpin;
    if (pushpin != null)
    {      
        this.isMapDoubleClickHandled = true;
        MessageBox.Show("pushpin_MouseDoubleClick");
    }
}
 
private void RadMap_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    if (!this.isMapDoubleClickHandled)
    {  
        MessageBox.Show("RadMap_OnMouseDoubleClick");
    }
    else
    {
        this.isMapDoubleClickHandled = false;
    }
}

Please give this approach a try and let me know if it works for you.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Etienne
Top achievements
Rank 1
answered on 28 Aug 2015, 06:23 PM

Hi Martin,

Thanks for your solution, it works great but I would have hope something more clean. Is it planned to improve RadMap so that double click event behave as expected ? That would be nice.

Thank you,

Etienne

0
Martin Ivanov
Telerik team
answered on 01 Sep 2015, 12:42 PM
Hello Etienne,

Actually, this behavior is expected in the WPF framework and we can't consider it as an unexpected behavior in the map. Handling the MouseDoubleClick event of a child element won't prevent the parent's MouseDoubleClick from firing. You can check this with nested ContentControl (or ItemsControl) elements. In order to prevent an element's event to bubble to its parent you can use the preview event. So, for your case you can try the following approach:
void radMap_InitializeCompleted(object sender, EventArgs e)
{
    if (!_initialized)
    {
        _initialized = true;
         
        // add pushpin
        var pushpin = new Pushpin();
        MapLayer.SetLocation(pushpin, new Location(40, -100));
        pushpin.PreviewMouseDoubleClick += pushpin_PreviewMouseDoubleClick; 
 
        informationLayer.Items.Add(pushpin);
    }
}
.
void pushpin_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    var pushpin = sender as Pushpin;
    if (pushpin != null)
    {
        e.Handled = true
        MessageBox.Show("pushpin_MouseDoubleClick");
    }
}

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Etienne
Top achievements
Rank 1
answered on 01 Sep 2015, 02:56 PM

Hi Martin,

Thanks for your reply, you're right. I had not realized that MouseDoubleClick is a direct event and not a bubble event. I'll try your approach.

Regards,

Etienne

Tags
Map
Asked by
Etienne
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Etienne
Top achievements
Rank 1
Share this question
or