ArcGIS API for Silverlight - Library Reference
Layers Property
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client Namespace > ArcGISDynamicMapServiceLayer Class : Layers Property

Gets an array of sub-layer information, known as LayerInfo objects, in an ArcGISDynamicMapServiceLayer.

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property Layers As LayerInfo()
C# 
public LayerInfo[] Layers {get;}

Remarks

Each LayerInfo in the array will provide the default visibility, unique ID, name, min/max scales, and a set of sub-layer IDs (if present).

Do not confuse the results of a Map.Layers Property (which returns a LayerCollection object) with the ArcGISDynamicMapServicelayer.Layers Property (which return a LayerInfo() object). A LayerCollection is an ObservableCollection of Layer objects used in displaying geographic information via symbols and text.

The following screen shot corresponds to the example code in this document. It displays an ArcGISDynamicMapServiceLayer and the asscociated text for interrogating the sub-layer information found in the ArcGISDynamicMapServiceLayer.Layers Property.

Interrogating the sub-layer information of an ArcGISDynamicMapServiceLayer.Layers Property.

Example

XAMLCopy Code
<StackPanel Name="StackPanel1" Height="400" Width="400" Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" >
    <esri:Map Background="White" Name="Map1" Height="200" Width="400">
    
         <!-- Define an ArcGISDynamicMapServiceLayer. -->
         <esri:ArcGISDynamicMapServiceLayer 
              Url="http://sampleserver1.arcgisonline.com:80/arcgis/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" />
              
    </esri:Map>
    
    <!-- Layers Property (Read Only) -->
    <!-- Get the name of the first sub-layer in the in the ArcGISDynamicMapServiceLayer -->
    <TextBlock Height="23" Name="TextBlock_Layers" Text="{Binding ElementName=Map1, Path=Layers[0].Layers[0].Name}" />
</StackPanel>
C#Copy Code
private void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
     
  // Create an ArcGISDynamicServiceLayer. The Map1 object (a Map class) was previously defined in XAML.
  ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer();
            	
  myArcGISDynamicMapServiceLayer.Url = "http://sampleserver1.arcgisonline.com:80/arcgis/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer";
  myArcGISDynamicMapServiceLayer.ID = "MyUniqueName";
  
  myArcGISDynamicMapServiceLayer.Initialized += new EventHandler<EventArgs>(ArcGISDynamicMapServiceLayer_Initialized);
  Map1.Layers.Add(myArcGISDynamicMapServiceLayer);
  
}
            	
private void ArcGISDynamicMapServiceLayer_Initialized(object sender, System.EventArgs e)
{
            	
  // The TextBlock_Layers (a TextBlock object) was defined previously in the XAML.
  ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (ArcGISDynamicMapServiceLayer)Map1.Layers["MyUniqueName"];
            	
  // Layers (Read Only)
  // Display the number of sub-layers and each sub-layer name in a textblock.
  ESRI.ArcGIS.Client.LayerInfo[] myLayerInfo = myArcGISDynamicMapServiceLayer.Layers;
  string myLayersText = "Number of sub-layers: " + myLayerInfo.Length.ToString();
  string myLayerstext2 = "";
  if (myLayerInfo.Length > 0)
  {
    int i = 0;
    for (i = 0; i  < myLayerInfo.Length; i++)
    {
      myLayerstext2 = myLayerstext2 + " " + myLayerInfo[i].Name;
    }
  }
  TextBlock_Layers.Text = myLayersText + ". Sub-layer Name's: " + myLayerstext2;
  
}
VB.NETCopy Code
Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
            	
  ' Create an ArcGISDynamicServiceLayer. The Map1 object (a Map class) was previously defined in XAML.
  Dim myArcGISDynamicMapServiceLayer As New ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer
 
  myArcGISDynamicMapServiceLayer.Url = "http://sampleserver1.arcgisonline.com:80/arcgis/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"
  myArcGISDynamicMapServiceLayer.ID = "MyUniqueName"
  
  AddHandler myArcGISDynamicMapServiceLayer.Initialized, AddressOf ArcGISDynamicMapServiceLayer_Initialized
  Map1.Layers.Add(myArcGISDynamicMapServiceLayer)
  
End Sub
            	
Private Sub ArcGISDynamicMapServiceLayer_Initialized(ByVal sender As System.Object, ByVal e As System.EventArgs)
            	
  ' The TextBlock_Layers (a TextBlock object) was defined previously in the XAML.
  Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer = Map1.Layers("MyUniqueName")
            	
  'Layers (Read Only)
  'Display the number of sub-layers and each sub-layer name in a textblock.
  Dim myLayerInfo() As ESRI.ArcGIS.Client.LayerInfo = myArcGISDynamicMapServiceLayer.Layers
  Dim myLayersText As String = "Number of sub-layers: " + myLayerInfo.Length.ToString
  Dim myLayerstext2 As String = ""
            	
  If myLayerInfo.Length > 0 Then
    Dim i As Integer
    For i = 0 To myLayerInfo.Length - 1
      myLayerstext2 = myLayerstext2 + " " + myLayerInfo(i).Name
    Next
  End If
            	
  TextBlock_Layers.Text = myLayersText + ". Sub-layer Name's: " + myLayerstext2
            	
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© ESRI, Inc. All Rights Reserved.