Graphics Actions

This sample demonstrates the redline, spatial query, and clear graphics actions. To use the redline action, click Redline from the menu in the upper right corner, then click and drag in the map to draw a line freehand. To use the spatial query, click Spatial Query in the menu and click and drag a query box in the map. To clear the Redline or Spatial Query graphics, use the menu's Clear buttons. In the sample XAML, the actions are attached to Buttons inside the Grid that comprises the menu. The key elements in the XAML are these Button elements. Examining these, you can see that these actions can be easily attached to a button's click event in XAML. The Redline action requires a color for the line, a draw mode (e.g. FreeHand), and the name of the target Map control. The Spatial Query action requires the ID of a GraphicsLayer for drawing the results, a symbol to apply to the result graphics, the URL to a layer or table to query, a draw mode to define how the query geometry is drawn, and the name of the target Map control. The Clear Graphics action only requires the ID of the GraphicsLayer to clear graphics from and the name of the Map control containing the GraphicsLayer.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.LocalGraphicsActions"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">
    <Grid x:Name="LayoutRoot" >
        <Grid.Resources>
            <LinearGradientBrush x:Key="PanelGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                <LinearGradientBrush.RelativeTransform>
                    <TransformGroup>
                        <ScaleTransform CenterY="0.5" CenterX="0.5"/>
                        <SkewTransform CenterY="0.5" CenterX="0.5"/>
                        <RotateTransform Angle="176" CenterY="0.5" CenterX="0.5"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </LinearGradientBrush.RelativeTransform>
                <GradientStop Color="#FF145787"/>
                <GradientStop Color="#FF3D7FAC" Offset="0.184"/>
                <GradientStop Color="#FF88C5EF" Offset="0.984"/>
            </LinearGradientBrush>
            <DropShadowEffect x:Name="dropShadow" BlurRadius="10" ShadowDepth="10" 
                              Direction="-45" Color="Black" Opacity="0.5" x:Key="dropShadow" />
            <Style x:Key="CommonBorder" TargetType="Border">
                <Setter Property="BorderBrush" Value="White" />
                <Setter Property="BorderThickness" Value="1" />
                <Setter Property="CornerRadius" Value="5" />
                <Setter Property="Background" Value="{StaticResource PanelGradient}" />
                <Setter Property="Opacity" Value="1" />
            </Style>            
            <esri:UniqueValueRenderer x:Key="GraphicsLayerLineSymbol">
                <esri:UniqueValueRenderer.DefaultSymbol>
                    <esri:SimpleLineSymbol Width="5">
                        <esri:SimpleLineSymbol.Color>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="Yellow" Offset="0"/>
                                <GradientStop Color="#FFB45050" Offset="1"/>
                            </LinearGradientBrush>
                        </esri:SimpleLineSymbol.Color>
                    </esri:SimpleLineSymbol>
                </esri:UniqueValueRenderer.DefaultSymbol>
            </esri:UniqueValueRenderer>
            <esri:SimpleFillSymbol x:Key="GraphicsLayerFillSymbol">
                <esri:SimpleFillSymbol.Fill>
                    <LinearGradientBrush x:Name="MyBrush" StartPoint="0,0" EndPoint="1,1">
                        <GradientStop Color="Yellow" Offset="0.0" />
                        <GradientStop Color="Red" Offset="0.25" />
                        <GradientStop Color="Blue" Offset="0.75" />
                        <GradientStop Color="LimeGreen" Offset="1.0" />
                    </LinearGradientBrush>
                </esri:SimpleFillSymbol.Fill>
            </esri:SimpleFillSymbol>
        </Grid.Resources>
        <esri:Map x:Name="MyMap" WrapAround="True"   Extent="-15000000,2000000,-7000000,8000000" MinimumResolution="2445.98490512499">
            <esri:ArcGISLocalTiledLayer ID="Shaded Relief" Path="..\\Data\\TPKs\\Topographic.tpk"/>
            <esri:GraphicsLayer ID="MyGraphicsLayer" Renderer="{StaticResource GraphicsLayerLineSymbol}" />
            <esri:GraphicsLayer ID="MyQueryResultsGraphicsLayer" Opacity="0.5" />
        </esri:Map>
        <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Width="Auto" Height="Auto" Margin="10" >
            <Border Style="{StaticResource CommonBorder}" Padding="10,3,10,10" Effect="{StaticResource dropShadow}">
                <StackPanel>
                    <TextBlock Text="Graphics Actions" Foreground="White" FontSize="14" FontWeight="Bold" Margin="4" />
                    <StackPanel Orientation="Horizontal" Margin="2">
                        <StackPanel Orientation="Vertical" Margin="2">
                            <Button Content="Redline" HorizontalAlignment="Left" Margin="2" Width="80">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <esri:RedlineAction 
                                    Color="#FF32FF00"
                                    DrawMode="Freehand"                                    
                                    GraphicsLayerID="MyGraphicsLayer" 
                                    TargetName="MyMap"/>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </Button>
                            <Button Content="Spatial Query" Margin="2" Width="80">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <esri:SpatialQueryAction
                                    DrawMode="Rectangle"
                                    LayerID="MyQueryResultsGraphicsLayer"                                    
                                    Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/2" 
                                    Symbol="{StaticResource GraphicsLayerFillSymbol}"
                                    TargetName="MyMap" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </Button>
                        </StackPanel>
                        <Line X1="0" Y1="0" X2="0" Y2="1" Stretch="Fill" Stroke="White" StrokeThickness="1" />
                        <StackPanel Orientation="Vertical" Margin="2">
                            <Button Content="Clear" Margin="2" HorizontalAlignment="Right" FontSize="12" Width="80">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <esri:ClearGraphicsAction 
                                    GraphicsLayerID="MyGraphicsLayer"
                                    TargetName="MyMap" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </Button>
                            <Button Content="Clear" FontSize="12" Margin="2" Width="80">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <esri:ClearGraphicsAction 
                                    GraphicsLayerID="MyQueryResultsGraphicsLayer"
                                    TargetName="MyMap" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </Button>
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
            </Border>
        </Grid>
    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014