wpf-116886-controls-and-libraries-map-control-end-user-interaction-map-selection.md
The Map control allows users to select items on the map surface.
Set the VectorLayerBase.EnableSelection property to true to allow end users to select vector layer items.
<dxm:VectorLayer EnableSelection="True">
<!--...-->
</dxm:VectorLayer>
When it is necessary to display the selected item above other layer items, set the VectorLayerBase.IncreaseItemZIndexInInteraction property to true.
<dxm:VectorLayer EnableSelection="True"
IncreaseItemZIndexInInteraction="True">
<!--...-->
</dxm:VectorLayer>
The following table demonstrates the IncreaseZIndexInInteraction property in action:
| Property value | Resulting image |
|---|---|
| IncreaseItemZIndexInInteraction = true | |
| IncreaseItemZIndexInInteraction = false |
Specify or obtain a selected item using the VectorLayerBase.SelectedItem property. When Multiple or Extended selection mode is enabled, it is possible to access selected items using the VectorLayerBase.SelectedItems property.
In addition, you can handle the MapControl.SelectionChanged event to provide specific actions each time the end user selects map control items.
// ...
mapControl.SelectionChanged += OnSelectionChanged;
// ...
void OnSelectionChanged(object sender, MapItemSelectionChangedEventArgs e) {
// Perform actions that should be done when selection changes.
}
' ...
AddHandler mapControl.SelectionChanged, AddressOf OnSelectionChanged
' ...
Sub OnSelectionChanged(sender As Object, e As MapItemSelectionChangedEventArgs)
' Perform actions that should be done when selection changes.
End Sub
The selection behavior is defined by its mode. The MapControl.SelectionMode property specifies which mode is enabled.
Set the SelectionMode property to Single. In this mode, only a single map item can be selected on the Map control surface.
To select an individual item on a map, perform one of the following actions.
The Map control makes it possible to mark any number of scattered vector items. To use this functionality:
SelectionMode property to Multiple.Extended mode joins Single and Multiple mode functionality. To enable Extended mode, set the SelectionMode property to Extended. Do the following to select items in Extended mode:
You can use the selection rectangle to select multiple map items at the same time. For this, perform the following steps:
SelectionMode property to Multiple or Extended.Shift key and left mouse button.Note
Click individual map items while pressing the Ctrl key to select or deselect them.
To configure rectangular selection settings, use the MapControl.SelectItemsByRegionBehavior property.
To configure the appearance of each individual item while it is selected, use the following properties.
Use the XAML below to add a MapEllipse object with specified selection settings to a map.
<dxm:VectorLayer>
<dxm:MapItemStorage>
<dxm:MapEllipse Location="70, -33"
Width="3500" Height="3500"
Fill="AliceBlue"
SelectedFill="Red"
SelectedStroke="Black">
<dxm:MapEllipse.SelectedStrokeStyle>
<dxm:StrokeStyle DashArray="10 2 4"
Thickness="5"
DashCap="Round"/>
</dxm:MapEllipse.SelectedStrokeStyle>
</dxm:MapEllipse>
</dxm:MapItemStorage>
</dxm:VectorLayer>
When you need to specify the common appearance settings for all selected items on a vector layer, use the following properties:
Use the XAML below to set a common appearance for the selected vector layer items.
<dxm:VectorLayer SelectedShapeFill="Coral"
SelectedShapeStroke="Black"/>
<dxm:VectorLayer.SelectedShapeStrokeStyle>
<dxm:StrokeStyle DashArray="1 3"
Thickness="2"
DashCap="Round"/>
</dxm:VectorLayer.SelectedShapeStrokeStyle>
<!--...-->
</dxm:VectorLayer>
See Also