Hey Jennifer, I tried to set binding to a feature datagrid at run-time through code-behind. I took your suggestion but the binding set seems not working because the datagrid disapear. Initially I bind it with a feature layer but at run time I need re-set the binding to other layers. Below is my code:
//binding feature datagrid to target layer
Binding bMap = new Binding("bMap");
bMap.Source = MyMap;
Binding bLayer = new Binding("bLayer");
bLayer.Source = MyMap.Layers["RegionLayer"];
MyDataGrid.SetBinding(FeatureDataGrid.MapProperty, bMap);
MyDataGrid.SetBinding(FeatureDataGrid.GraphicsLayerProperty, bLayer);
Initial setting for feature datagrid in XAML:
<esri:FeatureDataGrid x:Name="MyDataGrid" Background="White"
Map="{Binding ElementName=MyMap}"
GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[PPP_StateLayer]}" />
Any idea what's wrong?
I don't think you need a binding. You can directly set the Map and GraphicsLayer properties:MyDataGrid.Map = MyMap;
MyDataGrid.GraphicsLayer = MyMap.Layers["RegionLayer"];
Easier, no?:oSidenote : when you create a binding by code, the string in the binding constructor is supposed to be the 'Path'.So your code: Binding bMap = new Binding("bMap");
Binding bLayer = new Binding("bLayer");
should be: Binding bMap = new Binding("");
Binding bLayer = new Binding("");
bLayer.Source = MyMap.Layers["RegionLayer"];
orBinding bLayer = new Binding("Layers[RegionLayer]");bLayer.Source = MyMap;