Add Shapefiles and Rasters

This sample demonstrates using the dynamic layers capability in the ArcGIS Runtime SDK for WPF to add Shapefiles and Raster datasets to the map. Single or multiple Shapefiles or Rasters can be selected in the open file dialog from within a folder. These files will be added to a local map service via the dynamic layers capability available in the API. This local map service is then used as the basis for an ArcGISLocalDynamicMapServiceLayer which is added to the map. The application contains a basic legend to control the visibility of layers. It would be possible to extend the sample to allows users to specify the symbol/renderer for any shapefiles added. Raster symbology is predetermined by the raster itself. Notes: The dynamic layers functionality is not supported when the entire map has the accelerated display mode enabled. However, other layers could be accelerated via the AcceleratedDisplayLayers group layer.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.DynamicLayersDataSource"
             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">
    <Grid Background="AliceBlue">
        <Grid.Resources>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
            <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" Offset="0.16"/>
                <GradientStop Color="#FF3D7FAC" Offset="0.502"/>
                <GradientStop Color="#FF88C5EF" Offset="0.984"/>
            </LinearGradientBrush>
        </Grid.Resources>
        <esri:Map x:Name="_map">
            <!-- ArcGIS Online Tiled Basemap Layer -->
            <esri:ArcGISTiledMapServiceLayer ID="World Topographic Basemap (3857)" x:Name="_worldTopographicBasemap" 
                       Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
        </esri:Map>
        <Border BorderBrush="Black" CornerRadius="5" BorderThickness="1" Height="285" Width="175" HorizontalAlignment="Left" VerticalAlignment="Top" Background="{StaticResource PanelGradient}" Margin="10">
            <Border.Effect>
                <DropShadowEffect ShadowDepth="1" />
            </Border.Effect>
            <StackPanel>
                <TextBlock Text="Add Shapefile and raster data sample:" FontWeight="Bold" TextWrapping="Wrap" Foreground="White" Margin="5,5,5,0"/>
                <TextBlock Text="Click either the Add Shapefile or Add Raster button below then browse to a folder and select one or more datasets from that workspace to add them to the map." 
                           TextWrapping="Wrap" Foreground="White" Margin="5,5,5,0"/>
                <Button x:Name="AddShapefileButton" Click="AddShapefileButton_Click" ToolTip="Add Shapefile"
                        Height="64" HorizontalAlignment="Center" VerticalAlignment="Top" Width="64" Margin="5">
                    <Image Source="\Assets\Images\addvector.png"/>
                </Button>
                <Button x:Name="AddRasterButton" Click="AddRasterButton_Click" ToolTip="Add Raster"
                        Height="64" HorizontalAlignment="Center" VerticalAlignment="Top" Width="64" Margin="5,0,5,5">
                    <Image Source="\Assets\Images\addraster.png"/>
                </Button>
            </StackPanel>
        </Border>

        <Border Background="{StaticResource PanelGradient}"   BorderThickness="1" CornerRadius="5"
            HorizontalAlignment="Right"  VerticalAlignment="Top"
            Margin="10" Padding="5" BorderBrush="Black" >
            <Border.Effect>
                <DropShadowEffect/>
            </Border.Effect>
            <esri:Legend x:Name="_legend" 
                         Map="{Binding ElementName=_map}"                        
                         LayerItemsMode="Tree" 
                         ShowOnlyVisibleLayers="False"
                         Refreshed="Legend_Refreshed"
                         Background="#DDFFFFFF">
                <esri:Legend.MapLayerTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <CheckBox Content="{Binding Label}"
                                    IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                                    IsEnabled="{Binding IsInScaleRange}" Margin="5,5,5,0">
                            </CheckBox>
                            <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" Margin="5,5,5,5"/>
                        </StackPanel>
                    </DataTemplate>
                </esri:Legend.MapLayerTemplate>
                <esri:Legend.LayerTemplate>
                    <DataTemplate>
                        <CheckBox Content="{Binding Label}"
                            IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                            IsEnabled="{Binding IsInScaleRange}" Margin="5,0,5,5">
                        </CheckBox>
                    </DataTemplate>
                </esri:Legend.LayerTemplate>
            </esri:Legend>
        </Border>

    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014