FeatureLayer DataSource with FeatureDataGrid

This sample demonstrates how to use the DynamicLayer capability of the MapServer to create a new FeatureLayer object based on a Shapefile on disk and display the contents of the FeatureLayer in a FeatureDataGrid. In this example the MapServer is provided by the RuntimeLocalServer and therefore we have much greater control over the source of the data, in that it can be any Shapefile from any folder on disk. When working with ArcGIS for Server, the workspaces from which datasets are added must be preconfigured by the server administrator.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.DynamicLayersFeatureDataGrid"
             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"/>
           
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="5" />
            <RowDefinition Height="150" />
        </Grid.RowDefinitions>
        <esri:Map x:Name="MyMap" UseAcceleratedDisplay="True">
            <!-- 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" BorderThickness="1" Height="230" Width="175" HorizontalAlignment="Left" VerticalAlignment="Top" Background="White" Margin="10">
            <Border.Effect>
                <DropShadowEffect ShadowDepth="1" />
            </Border.Effect>
            <StackPanel>
                <TextBlock Text="Add Shapefile and display in FeatureDataGrid sample:" FontWeight="Bold" TextWrapping="Wrap"  Margin="5,5,5,0"/>
                <TextBlock Text="Click the Add Shapefile button below then browse to a folder and select one Shapefile from that workspace to add it to the map and 
                           display the attributes in the FeatureDataGrid." 
                           TextWrapping="Wrap"  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>
            </StackPanel>
        </Border>

        <Border Background="White"   BorderThickness="1" 
            HorizontalAlignment="Right"  VerticalAlignment="Top"
            Margin="10" Padding="5" BorderBrush="Black" >
            <Border.Effect>
                <DropShadowEffect/>
            </Border.Effect>
            <esri:Legend x:Name="_legend" 
                         Map="{Binding ElementName=MyMap}"                        
                         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>
        <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" />
        <esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid"
                Foreground="Black"/>
    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014