ArcGIS API for Windows Phone - Library Reference
MouseClick Event
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client Namespace > Map Class : MouseClick Event

The event handler that determines when the left mouse click has occurred in the Map Control.

Syntax

Visual Basic (Declaration) 
Public Event MouseClick As EventHandler(Of Map.MouseEventArgs)
C# 
public event EventHandler<Map.MouseEventArgs> MouseClick

Remarks

The Map.MouseClick Event is useful for capturing where the user clicked in the Map Control. The information obtained from the Map.MouseEventArgs can be useful for creating tools that perform actions such as:

  • Identifying what features are at that location
  • Drawing graphics where the user clicked
  • Showing the map and screen coordinates
  • Creating custom pan/zoom functionality
  • Finding the address where the user clicked
  • Creating routing stops or barriers
  • Executing geoprocessing functions that take a mouse click location as input

There are two scenarios that will invoke the event:

  • You click on the map with the left mouse button (i.e. an Identify).
  • You click on the map with the left mouse button and while you are holding the button down you use the scroll wheel to Zoom In/Out.

The Event will not fire if you are doing a mouse click and drag type of action (i.e. Pan, Zoom In/Out via Rectangle using the Shift or Ctrl+Shift keys).

Setting the Map.MouseEventArgs.Handled = True prevents most handlers along the Event route from handling the same Event again. The default setting of Map.MouseEventArgs.Handled = False leaves the routed Event unhandled, which permits the Event to potentially route further and be acted on by other handlers. For more information on routing Event handlers also known as "bubbling" see the Microsoft Silverlight document entitled MouseButtonEventArgs.Handled.

The Map.MouseEventArgs.WheelDelta will always be zero (0) in the Map.MouseClick Event. There is no way to capture Mouse Wheel changes programmatically. Additionally, the Map.MouseWheel Event never fires because it is being handled internally in the ArcGIS Silverlight source code.

Event Data

The event handler receives an argument of type Map.MouseEventArgs containing data related to this event. The following Map.MouseEventArgs properties provide information specific to this event.

PropertyDescription
Handled Gets or sets whether this event should continue to bubble.
MapPoint Gets or sets the point on the map where the event was raised
ScreenPoint Gets or sets the screen point where the event was raised
WheelDelta Gets or sets the amount the mouse wheel was scrolled

Example

How to use:

Click on the Map Control with the left mouse to see how the MouseClick Events provide information for the MouseEventArgs.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Demonstrating the obtaining the various MouseEventArgs values from the Map.MouseClick Event.

XAMLCopy Code
<Grid x:Name="LayoutRoot"  >
  
  <!-- Add a Map control with an ArcGISDymanicMapServiceLayer. Specify the use of the MouseClick Event. -->
  <esri:Map Background="White" HorizontalAlignment="Left" Name="Map1" VerticalAlignment="Top" 
            Height="426" Width="434" MouseClick="Map1_MouseClick" Margin="2,54,0,0">
    <esri:ArcGISDynamicMapServiceLayer Url="http://serverapps.esri.com/ArcGIS/rest/services/California/MapServer" />
  </esri:Map>
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="40" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="436" TextWrapping="Wrap" Margin="2,9,0,0" 
             Text="Click on the Map Control with the left mouse to see how the MouseClick Events provide information for the MouseEventArgs." />
  
  <!-- Show the information for the Handled Property. -->
  <StackPanel Height="24" HorizontalAlignment="Left" Margin="440,54,0,0" Name="StackPanel1" 
              VerticalAlignment="Top" Width="200" >
    <Grid Name="Grid1">
      <Grid.RowDefinitions>
        <RowDefinition Height="24"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="60"/>
        <ColumnDefinition Width="160"/>
      </Grid.ColumnDefinitions>
      <sdk:Label Grid.Row="0" Grid.Column="0" Content="Handled:" FontWeight="Bold"/>
      <sdk:Label Grid.Row="0" Grid.Column="1" Name="Handled"/>
    </Grid>
  </StackPanel>
  
  <!-- Show the information for the MapPoint Property. -->
  <StackPanel Height="265" HorizontalAlignment="Left" Margin="440,100,0,0" Name="StackPanel2" 
              VerticalAlignment="Top" Width="200" >
    <sdk:Label Height="24" Width="120" Content="MapPoint:" HorizontalAlignment="Left" FontWeight="Bold" />
    <sdk:Label Height="24" Width="120" Content="Extent"  HorizontalAlignment="Left"/>
    <Grid Name="Grid2">
      <Grid.RowDefinitions>
        <RowDefinition Height="24"/>
        <RowDefinition Height="24"/>
        <RowDefinition Height="24"/>
        <RowDefinition Height="24"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="40"/>
        <ColumnDefinition Width="160"/>
      </Grid.ColumnDefinitions>
      <sdk:Label Grid.Row="0" Grid.Column="0" Content="XMin:"/>
      <sdk:Label Grid.Row="0" Grid.Column="1" Name="MapPoint_Extent_XMin"/>
      <sdk:Label Grid.Row="1" Grid.Column="0" Content="XMax:"/>
      <sdk:Label Grid.Row="1" Grid.Column="1" Name="MapPoint_Extent_XMax" />
      <sdk:Label Grid.Row="2" Grid.Column="0" Content="YMin:"/>
      <sdk:Label Grid.Row="2" Grid.Column="1" Name="MapPoint_Extent_YMin"/>
      <sdk:Label Grid.Row="3" Grid.Column="0" Content="YMin:"/>
      <sdk:Label Grid.Row="3" Grid.Column="1" Name="MapPoint_Extent_YMax" />
    </Grid>
    <sdk:Label Height="24" Width="120" Content="SpatialReference"  HorizontalAlignment="Left"/>
    <Grid Name="Grid3">
      <Grid.RowDefinitions>
        <RowDefinition Height="24"/>
        <RowDefinition Height="24"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="40"/>
        <ColumnDefinition Width="160"/>
      </Grid.ColumnDefinitions>
      <sdk:Label Grid.Row="0" Grid.Column="0" Content="WKID:"/>
      <sdk:Label Grid.Row="0" Grid.Column="1" Name="MapPoint_SpatialReference_WKID"/>
      <sdk:Label Grid.Row="1" Grid.Column="0" Content="WKT:"/>
      <sdk:Label Grid.Row="1" Grid.Column="1" Name="MapPoint_SpatialReference_WKT" />
    </Grid>
    <Grid Name="Grid4">
      <Grid.RowDefinitions>
        <RowDefinition Height="24"/>
        <RowDefinition Height="24"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="40"/>
        <ColumnDefinition Width="160"/>
      </Grid.ColumnDefinitions>
      <sdk:Label Grid.Row="0" Grid.Column="0" Content="X:"/>
      <sdk:Label Grid.Row="0" Grid.Column="1" Name="MapPoint_X"/>
      <sdk:Label Grid.Row="1" Grid.Column="0" Content="Y:"/>
      <sdk:Label Grid.Row="1" Grid.Column="1" Name="MapPoint_Y" />
    </Grid>
  </StackPanel>
  
  <!-- Show the information for the ScreenPoint Property. -->
  <StackPanel Height="72" HorizontalAlignment="Left" Margin="440,375,0,0" Name="StackPanel3" 
              VerticalAlignment="Top" Width="200" >
    <sdk:Label Height="24" Width="120" Content="ScreenPoint:" HorizontalAlignment="Left" FontWeight="Bold"/>
    <Grid Name="Grid5">
      <Grid.RowDefinitions>
        <RowDefinition Height="24"/>
        <RowDefinition Height="24"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="60"/>
        <ColumnDefinition Width="160"/>
      </Grid.ColumnDefinitions>
      <sdk:Label Grid.Row="0" Grid.Column="0" Content="X:"/>
      <sdk:Label Grid.Row="0" Grid.Column="1" Name="ScreenPoint_X"/>
      <sdk:Label Grid.Row="1" Grid.Column="0" Content="Y:"/>
      <sdk:Label Grid.Row="1" Grid.Column="1" Name="ScreenPoint_Y"/>
    </Grid>
  </StackPanel>
  
  <!-- Show the information for the WheelDelta Property. -->
  <StackPanel Height="24" HorizontalAlignment="Left" Margin="440,455,0,0" Name="StackPanel4" 
              VerticalAlignment="Top" Width="200" >
    <Grid Name="Grid6">
      <Grid.RowDefinitions>
        <RowDefinition Height="24"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="80"/>
        <ColumnDefinition Width="160"/>
      </Grid.ColumnDefinitions>
      <sdk:Label Grid.Row="0" Grid.Column="0" Content="WheelDelta:" FontWeight="Bold"/>
      <sdk:Label Grid.Row="0" Grid.Column="1" Name="WheelDelta"/>
    </Grid>
  </StackPanel>
  
</Grid>
C#Copy Code
private void Map1_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
{
            
  // Use local variables to obtain the e arguments.
  bool myHandled = e.Handled;
  ESRI.ArcGIS.Client.Geometry.MapPoint myMapPoint = e.MapPoint;
  System.Windows.Point myScreenPoint = e.ScreenPoint;
  double myWheelDelta = e.WheelDelta;
  
  // Display the results from the Map.MouseClick Event.
  // --------------------------------------------------
  Handled.Content = myHandled.ToString();
  
  MapPoint_Extent_XMax.Content = myMapPoint.Extent.XMax.ToString();
  MapPoint_Extent_XMin.Content = myMapPoint.Extent.XMin.ToString();
  MapPoint_Extent_YMax.Content = myMapPoint.Extent.YMax.ToString();
  MapPoint_Extent_YMin.Content = myMapPoint.Extent.YMin.ToString();
  
  if ((myMapPoint.SpatialReference) != null)
  {
    MapPoint_SpatialReference_WKID.Content = myMapPoint.SpatialReference.WKID.ToString();
    MapPoint_SpatialReference_WKT.Content = myMapPoint.SpatialReference.WKT;
  }
            
  MapPoint_X.Content = myMapPoint.X.ToString();
  MapPoint_Y.Content = myMapPoint.Y.ToString();
  
  ScreenPoint_X.Content = myScreenPoint.X.ToString();
  ScreenPoint_Y.Content = myScreenPoint.Y.ToString();
  
  WheelDelta.Content = myWheelDelta.ToString();
  
}
VB.NETCopy Code
Private Sub Map1_MouseClick(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Client.Map.MouseEventArgs)
             
  ' Use local variables to obtain the e arguments.
  Dim myHandled As Boolean = e.Handled
  Dim myMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint = e.MapPoint
  Dim myScreenPoint As System.Windows.Point = e.ScreenPoint
  Dim myWheelDelta As Double = e.WheelDelta
  
  ' Display the results from the Map.MouseClick Event.
  ' --------------------------------------------------
  Handled.Content = myHandled.ToString
  
  MapPoint_Extent_XMax.Content = myMapPoint.Extent.XMax.ToString
  MapPoint_Extent_XMin.Content = myMapPoint.Extent.XMin.ToString
  MapPoint_Extent_YMax.Content = myMapPoint.Extent.YMax.ToString
  MapPoint_Extent_YMin.Content = myMapPoint.Extent.YMin.ToString
  
  If (myMapPoint.SpatialReference) IsNot Nothing Then
    MapPoint_SpatialReference_WKID.Content = myMapPoint.SpatialReference.WKID.ToString
    MapPoint_SpatialReference_WKT.Content = myMapPoint.SpatialReference.WKT
  End If
  
  MapPoint_X.Content = myMapPoint.X.ToString
  MapPoint_Y.Content = myMapPoint.Y.ToString
  
  ScreenPoint_X.Content = myScreenPoint.X.ToString
  ScreenPoint_Y.Content = myScreenPoint.Y.ToString
  
  WheelDelta.Content = myWheelDelta.ToString
  
End Sub

Requirements

Target Platforms:Windows Phone 7

See Also

© ESRI, Inc. All Rights Reserved.