Morten, Iam using following sample link example to display my layers in the TOC to turnon and turnoff the layers (in ArcGISDynamicMapServiceLayer).http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SubLayerListI am able to see the layers list with the checkboxes but when I click on any of the layers checkboxes to turnon or turnoff the layers nothing happens. i.e. Layers are still there on the map. Below is my code snippet. My mxd file contains some group layers also. Is that the problem or anything else. I will appreciate your reply. Sanjay.<Grid x:Name="LayoutRoot">
<esri:Map x:Name="MyMap">
<esri:ArcGISDynamicMapServiceLayer ID="MyLayers"
Url="http://srajput/arcgis/rest/services/LCEC20/MapServer"
Initialized="ArcGISDynamicMapServiceLayer_Initialized" />
</esri:Map>
<Border Background="#779DE26F" BorderThickness="1" CornerRadius="5"
HorizontalAlignment="Right" VerticalAlignment="Top"
Margin="20,20,20,30" Padding="10" BorderBrush="Black">
<Border.Effect>
<DropShadowEffect/>
</Border.Effect>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="15" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Layers in LCEC20" FontWeight="Bold" Grid.Row="0" />
<ListBox Margin="0,5,0,0" ItemsSource="{Binding ElementName=MyMap, Path=Layers.[0].Layers}"
Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Margin="2"
Name="MyLayers"
Content="{Binding Name}"
IsChecked="{Binding DefaultVisibility}"
Tag="{Binding ID}"
ClickMode="Press"
Click="CheckBox_Click" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Border>
</Grid>
CODE BEHIND FILE:
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
CheckBox tickedCheckBox = sender as CheckBox;
string serviceName = tickedCheckBox.Name;
bool visible = (bool)tickedCheckBox.IsChecked;
int layerIndex = (int)tickedCheckBox.Tag;
ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicServiceLayer = MyMap.Layers[serviceName] as
ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer;
List<int> visibleLayerList =
dynamicServiceLayer.VisibleLayers != null
? dynamicServiceLayer.VisibleLayers.ToList() : new List<int>();
if (visible)
{
if (!visibleLayerList.Contains(layerIndex))
visibleLayerList.Add(layerIndex);
}
else
{
if (visibleLayerList.Contains(layerIndex))
visibleLayerList.Remove(layerIndex);
}
dynamicServiceLayer.VisibleLayers = visibleLayerList.ToArray();
}
private void ArcGISDynamicMapServiceLayer_Initialized(object sender, EventArgs e)
{
ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicServiceLayer =
sender as ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer;
if (dynamicServiceLayer.VisibleLayers == null)
dynamicServiceLayer.VisibleLayers = GetDefaultVisibleLayers(dynamicServiceLayer);
}
private int[] GetDefaultVisibleLayers(ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicService)
{
List<int> visibleLayerIDList = new List<int>();
ESRI.ArcGIS.Client.LayerInfo[] layerInfoArray = dynamicService.Layers;
for (int index = 0; index < layerInfoArray.Length; index++)
{
if (layerInfoArray[index].DefaultVisibility)
visibleLayerIDList.Add(index);
}
return visibleLayerIDList.ToArray();
}