Select to view content in your preferred language

Handle double click on graphics layer

1238
3
Jump to solution
05-08-2012 08:55 AM
MarkCollins
Frequent Contributor
I am looking for an event or some way to handle double click on a graphics layer or more specific on my features in a feature layer.

Any one done this before or have any ideas? I know this sounds super simple but I can not find an event handler for it....

Thanks,
Mark
0 Kudos
1 Solution

Accepted Solutions
dotMorten_esri
Esri Notable Contributor
If you are using Silverlight 5, you could also use the Map.MouseLeftButtonDown event and check the ClickCount property. Example:

   private void MyMap_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)  {   if (e.ClickCount == 2)   {    var graphicslayer = MyMap.Layers.OfType<GraphicsLayer>().First(); //Grab graphics layer    var graphics = graphicslayer.FindGraphicsInHostCoordinates(e.GetPosition(null)); //find any graphics over clickpoint    var topGraphic = graphics.FirstOrDefault(); //grab the first hit    if (topGraphic != null) //we hit a graphic    {     e.Handled = true; //prevent map from zooming     MessageBox.Show("You dbl clicked a graphic");    }   }  }

View solution in original post

0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
You can do something like this. But you might also want to consider click tolerance besides checking for same graphic and elapsed time since last click.

    Graphic graphic;
    TimeSpan elapsedTime;
    DateTime? startTime;
    private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)
    {
     if (graphic == null || graphic != e.Graphic)
     {
      graphic = e.Graphic;
      startTime = DateTime.Now;
     }
     else if (graphic == e.Graphic && startTime.HasValue)
     {
      elapsedTime = DateTime.Now.Subtract(startTime.Value);
      if (elapsedTime.TotalMilliseconds < 500)
      {
       
       //double click happened
      }

      graphic = null;
      startTime = null;
     }
    }
0 Kudos
dotMorten_esri
Esri Notable Contributor
If you are using Silverlight 5, you could also use the Map.MouseLeftButtonDown event and check the ClickCount property. Example:

   private void MyMap_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)  {   if (e.ClickCount == 2)   {    var graphicslayer = MyMap.Layers.OfType<GraphicsLayer>().First(); //Grab graphics layer    var graphics = graphicslayer.FindGraphicsInHostCoordinates(e.GetPosition(null)); //find any graphics over clickpoint    var topGraphic = graphics.FirstOrDefault(); //grab the first hit    if (topGraphic != null) //we hit a graphic    {     e.Handled = true; //prevent map from zooming     MessageBox.Show("You dbl clicked a graphic");    }   }  }
0 Kudos
MarkCollins
Frequent Contributor
Excellent, thank you both!
0 Kudos