Layer Actions

This sample demonstrates the Toggle Layer, Update Feature Layer, and Zoom to Layer actions. To use each of these actions, simply click the corresponding item from the menu in the upper right corner of the application. The Toggle Layer action toggles the visibility of the states layer. The Update Feature Layer action refreshes the clustered feature layer. The Zoom To Layer action zooms to the feature layer. 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 and the actions they contain. Examining these, you can see that these actions can be easily attached to a button's click event in XAML. Each of these actions only require the ID of the layer to target and the name of the Map control containing the layer.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.LocalLayerActions"
    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>
            <esri:SimpleRenderer x:Key="MySimplePolygonRenderer">
                <esri:SimpleRenderer.Symbol>
                    <esri:SimpleFillSymbol Fill="#440000FF"/>
                </esri:SimpleRenderer.Symbol>
            </esri:SimpleRenderer>
            <DropShadowEffect x:Name="dropShadow" BlurRadius="10" ShadowDepth="10" 
                              Direction="-45" Color="Black" Opacity="0.5" x:Key="dropShadow" />
            <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>
            <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:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="10" Style="Circle" />
        </Grid.Resources>
        <esri:Map x:Name="MyMap" WrapAround="True"  Extent="-15000000,2000000,-7000000,8000000" MinimumResolution="2445.98490512499">
            <esri:ArcGISLocalTiledLayer ID="MyBaseLayer" Path="..\\Data\\TPKs\\Topographic.tpk"/>
            <esri:ArcGISLocalFeatureLayer ID="MyFeatureLayer" Path="..\\Data\\DynamicLayers\\USA.mpk" LayerName="States" OutFields="*" Renderer="{StaticResource MySimplePolygonRenderer}">
                <esri:ArcGISLocalFeatureLayer.Clusterer>
                    <esri:FlareClusterer />
                </esri:ArcGISLocalFeatureLayer.Clusterer>
            </esri:ArcGISLocalFeatureLayer>
        </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="Layer Actions" Foreground="White" FontSize="14" FontWeight="Bold" Margin="4" />
                    <Button Content="Toggle Layer Visibility" Margin="2" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <esri:ToggleLayerAction 
                                    LayerID="MyFeatureLayer"
                                    TargetName="MyMap"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Button>
                    <Button Content="Update Feature Layer" Margin="2" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger PreviewInvoke="EventTrigger_PreviewInvoke"
                              EventName="Click">
                                <esri:UpdateFeatureLayerAction 
                              FeatureLayerID="MyFeatureLayer"                                    
                              TargetName="MyMap" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Button>
                    <Button Content="Zoom To Layer" Margin="2" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <esri:ZoomToLayerAction
                  LayerID="MyFeatureLayer"
                  TargetName="MyMap" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Button>
                </StackPanel>
            </Border>
        </Grid>
    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014