Add Layer Dynamically

This sample demonstrates how to add an ArcGISLocalTiledLayer dynamically. This sample includes a Map with no layers. Enter the path to an ArcGIS Local Tile package (.tpk) and click the Add Layer button to add the local tiled layer to the map. The map will also zoom to the initial extent of the layer.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.LocalAddLayerDynamically"
    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 x:Name="LayoutRoot" Background="White">
        <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" Offset="0.16"/>
                <GradientStop Color="#FF3D7FAC" Offset="0.502"/>
                <GradientStop Color="#FF88C5EF" Offset="0.984"/>
            </LinearGradientBrush>
        </Grid.Resources>
        <esri:Map x:Name="MyMap" ExtentChanged="MyMap_ExtentChange" ExtentChanging="MyMap_ExtentChange" WrapAround="True" Background="#FFE3E3E3"/>
        <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,15,0" Height="118"  >
            <Rectangle Fill="{StaticResource PanelGradient}" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0,0,0,5">
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <Rectangle Fill="#DDFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
            <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="0,20,30,30">
                <TextBlock Foreground="Black" FontWeight="Bold" HorizontalAlignment="Center" Text="Enter path to Tile Package." />
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" >
                    <TextBlock Text="Path: " Width="80" TextAlignment="Right" VerticalAlignment="Center" Foreground="Black"/>
                    <TextBox x:Name="UrlTextBox" Text="..\\Data\\TPKs\\Topographic.tpk" Width="550"/>
                </StackPanel>
                <Button x:Name="AddLayerButton" Content="Add Layer" Width="100" Margin="0,5,0,0" HorizontalAlignment="Center" Click="AddLayerButton_Click" />
            </StackPanel>
        </Grid>
        <Grid x:Name="ExtentGrid" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="10" Visibility="Collapsed" >
            <Rectangle Fill="{StaticResource PanelGradient}" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <StackPanel Orientation="Vertical" Margin="10">
                <TextBlock x:Name="ExtentTextBlock" Text="Extent: " Margin="5" TextWrapping="Wrap" FontWeight="Bold" Foreground="White"  />
                <TextBox x:Name="ExtentTextBox" IsReadOnly="True" Margin="5" />
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014