Are you using this sample? http://help.arcgis.com/en/webapi/silverlight/1.2/samples/start.htm#FeatureDataGrid.
If you had been using the samples from v2.1: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitFeatureDataGrid. The XAML Parse Exception could be caused by the Binding statements that are not yet supported in VS 2008. If you were using the latter sample, please use the first link instead.
Binding mapBinding = new Binding(); mapBinding.Source = MyMap; MyDataGrid.SetBinding(FeatureDataGrid.MapProperty, mapBinding); Binding graphicsLayerBinding = new Binding("Layers.[1]"); graphicsLayerBinding.Source = MyMap; MyDataGrid.SetBinding(FeatureDataGrid.GraphicsLayerProperty, graphicsLayerBinding);
MyDataGrid.Map = MyMap; MyDataGrid.GraphicsLayer = MyMap.Layers[1] as GraphicsLayer;
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
MyDataGrid.Visibility = Visibility.Visible;
Binding mapBinding = new Binding();
mapBinding.Source = MyMap;
MyDataGrid.SetBinding(FeatureDataGrid.MapProperty, mapBinding);
Binding graphicsLayerBinding = new Binding("Layers.[1]");
graphicsLayerBinding.Source = MyMap;
MyDataGrid.SetBinding(FeatureDataGrid.GraphicsLayerProperty, graphicsLayerBinding);
MyDataGrid.UpdateLayout();
}
private void FeatureLayer_MouseLeftButtonDown(object sender, Graphic graphic, MouseButtonEventArgs args)
{
graphic.Selected = !graphic.Selected;
if (graphic.Selected)
MyDataGrid.ScrollIntoView(graphic, null);
}
}
<UserControl x:Class="SilverlightApplication2.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:esri="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client"
xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client"
xmlns:esriToolkit="clr-namespace:ESRI.ArcGIS.Client.Toolkit;assembly=ESRI.ArcGIS.Client.Toolkit" >
<Grid x:Name="LayoutRoot" Background="White">
<Grid.Resources>
<esriSymbols:SimpleFillSymbol x:Name="SelectSymbol">
<esriSymbols:SimpleFillSymbol.ControlTemplate>
<ControlTemplate>
<Path x:Name="Element" Fill="#330000FF" Stroke="Black" StrokeThickness="1"
Cursor="Hand">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected" />
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimation Storyboard.TargetName="Element"
Storyboard.TargetProperty="(Path.Fill).(SolidColorBrush.Color)"
To="#99FFFF00" Duration="0:0:.25" />
<ColorAnimation Storyboard.TargetName="Element"
Storyboard.TargetProperty="(Path.Stroke).(SolidColorBrush.Color)"
To="#9900FFFF" Duration="0:0:.25" />
<DoubleAnimation Storyboard.TargetName="Element"
Storyboard.TargetProperty="StrokeThickness"
To="3" Duration="00:00:.25" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Path>
</ControlTemplate>
</esriSymbols:SimpleFillSymbol.ControlTemplate>
</esriSymbols:SimpleFillSymbol>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="5" />
<RowDefinition Height="150" />
</Grid.RowDefinitions>
<esri:Map x:Name="MyMap" Background="White" Extent="-125,32,-114,42">
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
<esri:FeatureLayer FeatureSymbol="{StaticResource SelectSymbol}"
Url="http://serverapps.esri.com/ArcGIS/rest/services/California/MapServer/8"
MouseLeftButtonDown="FeatureLayer_MouseLeftButtonDown">
<esri:FeatureLayer.OutFields>
<sys:String>*</sys:String>
</esri:FeatureLayer.OutFields>
</esri:FeatureLayer>
</esri:Map.Layers>
</esri:Map>
<basics:GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" />
<esriToolkit:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid" Visibility="Collapsed"/>
</Grid>
</UserControl>
System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: System.Windows.Markup.XamlParseException: AG_E_PARSER_BAD_TYPE [Line: 89 Position: 164]
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight) [Line: 0 Position: 0]
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight) [Line: 0 Position: 0]
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight) [Line: 0 Position: 0]
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight) [Line: 0 Position: 0]
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight) [Line: 0 Position: 0]
You should be using the 1.2 sample (1st link from post#2).
One of the key differences in the two samples:
in 1.2 (VS 2008)
<esriToolkit:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid"
Map="{Binding ElementName=MyMap}"
GraphicsLayer="{Binding ElementName=MyMap, Path= Layers.[1]}" />
in 2.0 (VS 2010)
<esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid"
Map="{Binding ElementName=MyMap}"
GraphicsLayer="{Binding ElementName=MyMap, Path= Layers.[California]}" />
The equivalent code-behind binding is:
Binding mapBinding = new Binding(); mapBinding.Source = MyMap; MyDataGrid.SetBinding(FeatureDataGrid.MapProperty, mapBinding); Binding graphicsLayerBinding = new Binding("Layers.[1]"); graphicsLayerBinding.Source = MyMap; MyDataGrid.SetBinding(FeatureDataGrid.GraphicsLayerProperty, graphicsLayerBinding);
If you don't require binding, you can simply set these properties:
MyDataGrid.Map = MyMap; MyDataGrid.GraphicsLayer = MyMap.Layers[1] as GraphicsLayer;