Microsoft Expression Blend 4 defines a standard for behaviors, which are reusable pieces of packaged code that can be dragged onto any object and fine-tuned by changing their properties. Behaviors allow you to add interactivity to your applications without having to write any code. The Behavior API consists of three core classes: Trigger, Action, and Behavior. The ArcGIS API for Silverlight includes a set of behaviors and actions in the ESRI.ArcGIS.Client.Behaviors assembly that can be used to define interactive relationships between user input and map behavior and content.
To use behaviors and actions in your application, you must add a reference to the System.Windows.Interactivity assembly. This assembly is included with the Expression Blend 4 product or the Expression Blend 4 SDK (currently included with Expression Blend 4).
In all code examples below, references to the System.Windows.Interactivity, ESRI.ArcGIS.Client, and ESRI.ArcGIS.Client.Behaviors assemblies were added to the project, and a namespace reference for each was added to the page:
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
xmlns:esriBehaviors="clr-namespace:ESRI.ArcGIS.Client.Behaviors;assembly=ESRI.ArcGIS.Client.Behaviors"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Behaviors
A behavior is composed of a trigger and an action for a specific control. All behaviors included with the ArcGIS API for Silverlight are designed to work with a predefined event on the map (trigger) that generates (action) a result. The behaviors are packaged for you; therefore, you only need to add a behavior to a map to use it. The table below lists the map behaviors, provides a description, and shows a code example for each:
Behavior |
Description |
Code example |
---|---|---|
ConstrainExtentBehavior |
Limit the map extent to an envelope. The user cannot navigate outside the envelope defined in the behavior. |
|
MaintainExtentBehavior |
Maintain the current extent when the map is resized. |
|
ShowCoordinatesBehavior |
Show map coordinates next to the mouse cursor when hovering the mouse pointer over the map. |
|
Actions
An action is composed of a trigger and a target. The trigger is an event, such as the click event of a button. A target is where the results of the action are used or displayed. Actions included with the ArcGIS API for Silverlight will always target the map and its contents. Actions include adding graphics, navigating the map, and working with layers. The table below lists available actions, provides a description, and shows a code example for each:
Action |
Description |
Code example |
---|---|---|
ClearGraphicsAction |
Clear all graphics in a graphics layer. |
|
MeasureAction |
Show measure distance, radius, and area. |
|
PanToAction |
Pan to a specified geometry. |
|
RedlineAction |
Draw graphics on the map and add them to a graphics layer. |
|
SpatialQueryAction |
Draw geometry on the map to query features in a feature layer. Draw the results in a graphics layer. |
|
ToggleLayerAction |
Toggle the visibility of a layer. |
|
UpdateFeatureLayerAction |
Refresh the contents of a feature layer. |
|
ZoomToAction |
Zoom to a specified geometry. If the geometry is a point, the map will pan. |
|
ZoomToFullExtentAction |
Zoom to the full extent of all layers. |
|
ZoomToLayerAction |
Zoom to the extent of a specified layer. |
|