ArcGIS API for Silverlight - Library Reference
Attribution Class
Members  Example  See Also  Send comments on this topic
ESRI.ArcGIS.Client.Toolkit Namespace : Attribution Class

The Attribution Control displays Copyright information for Layers that have the IAttribution Interface implemented.

Object Model

Attribution ClassLayerCollection ClassLayer Class

Syntax

Visual Basic (Declaration) 
Public Class Attribution 
   Inherits System.Windows.Controls.Control
C# 
public class Attribution : System.Windows.Controls.Control 

Remarks

The Attribution Control is a User Interface (UI) control that displays Copyright information in a list of Microsoft ContentPresenter Controls for each Layer in a LayerCollection that has the IAttribution Interface implemented. Layers that have the IAttribution Interface implemented have an additional .AttributionTemplate Property which returns a DataTemplate that allows for the display of the Copyright information in the ContentPresenter. As of version 2.2 of the API, the Copyright information is returned as CopyrightText strings for the various Layers that implement the IAttribution interface.

The Attribution Control can be created at design-time in XAML or dynamically at run-time in the code-behind. The Attribution Control is one of several controls available in the Toolbox for Visual Studio when the ArcGIS API for Silverlight is installed, see the following screen shot:

Example of the Attribution Control on the XAML design surface of a Silverlight application.

The default appearance of the Attribution Control can be modified using numerous inherited Properties from System.Windows.FrameworkElement, System.Windows.UIElement, and System.Windows.Controls. An example of some of these Properties include: .Height, .Width, .BackGround, .BorderBrush, .BorderThickness, .FontFamily, .FontSize, .FontStretch, .FontStyle, .Foreground, .HorizontalAlignment, .VerticalAlignment, .Margin, .Opacity, .Visibility, etc.

Note: you cannot change the core behavior of the sub-components (i.e. ContentPresenter, etc.) of the Attribution Control using standard Properties or Methods alone. To change the core behavior of the sub-components and their appearance of the Control, developers can modify the Control Template in XAML and the associated code-behind file. The easiest way to modify the UI sub-components is using Microsoft Expression Blend. Then developers can delete/modify existing or add new sub-components in Visual Studio to create a truly customized experience. A general approach to customizing a Control Template is discussed in the ESRI blog entitled: Use control templates to customize the look and feel of ArcGIS controls. A specific code example of modifying the Control Template of the Attribution Control can be found in the Attribution.Layers documentation.

The Attribution Control is comprised of mainly one sub-component, a ContentPresenter, that displays Copyright information for each Layer that has the IAttribution Interface implemented. The implied Binding that occurs in the ControlTemplate Style of the Attribution Control to the ContentPresenter sub-component is to the ESRI.ArcGIS.Client.IAttribution Interface members. The IAttribution Interface adds functionality to Layer objects. These special Layer Types have an .AttributionTemplate Property. The .AttributionTemplate Property is the internal mechanism for constructing the IAttribution object. Only those Layers which have a .AttributionTemplate Property will get listed in the ObservabaleCollection(Of IAttribution) as a result of using the Attribution.Items Property. The following Layers are those that implement the IAttribution Interface and have an .AttributionTemplate Property:

Note: This also means that you can also use implied Binding in the ControlTemplate Style of the Attribution Control for the various Properties of the special Types of Layers such as: .ID, .Url, .Version, etc.

The Attribution.Items Property returns a Read only ObservableCollection(Of IAttribution) object. While it is true that you can use the various ObservableCollection Propeties such as .Add, .Clear, .Remove, etc. to manipulate the contents of what is in the ObservableCollection it is not recommended. The Attribution.PropertyChanged and Attribution.Refreshed Events do not fire as a result of adding/removing items in the ObservableCollection. Additionally, the Map Control does not update by adding/removing items in the ObservableCollection. The correct programming practice to see automatic updates to the Attributon.Items Collection is to add Layers to the Map Control which is bound to the Attribution.Layers. When Binding the Map.Layers to the Attribution.Layers is done any .Add, .Remove, or change to the LayerCollection will result in update to Attribution.Items.

Both the Attribution.PropertyChanged and Attribution.Refreshed Events fire as a result of the Layers that Implement IAttribution in the LayerCollection being added or removed in the Attribution.Layers Property. Use the Attribution.Refreshed Event if you want to add, delete, or modify the default attribution items given by the framework. Use the Attribution.PropertyChanged Event on property Attribution.Items, if you want to be aware of this change in order to hook up an Event fired by Attribution.Items. Note: The various special Layer types that Implement the IAttribution Interface have Copyright information Properties that are ReadOnly (meaning they can't be changed by the client application) and hence it is impossible force the Attribution.PropertyChanged and Attribution.Refreshed Events to update as a result of trying to modify the Copyright information on the client side.

In order to use the Attribution Control it is mandatory that the Attribution.Layers Property be set to a valid LayerCollection. This can be done via Binding in the XAML or by setting the Attribution.Layers Property in the code-behind file. Typically, the LayerCollection object is obtained from the Layers Property on the Map Control.

In the following XAML example, Binding is used to associate a Map Control named 'Map1' with it’s LayerCollection to the Attribution Control’s Layers Property:

            <esri:Attribution Name="Attribution1" Layers="{Binding ElementName=Map1,Path=Layers}" />
            

The default visual appearance of the Attribution Control is minimal when using drag-and-drop to place the control on the design surface of a XAML page in Visual Studio; there are graphical selection handles but nothing else to denote the visual appearance of the control. At design-time, it is not until the Attribution.Layers Property is specified that placeholder text values will be populated in the control. At design-time, if no ID value is specified for the Layer the placeholder information displayed in the list of ContentPresenter sub-controls will be of the form: "<Type of Layer> attribution.". Conversely, if there is an ID value specified for the Layer the placeholder information displayed in the list of ContentPresenter sub-controls will be of the form: "<Layer ID> attribution.". See the following screen shot to see how the design-time placeholder text appears in the Attribution Control for the associated XAML:

Example of the visual appearance of the Attribution Control at design-time when the Attribution.Layers Property is bound to the Map.Layers Property.

NOTE: It is not until run-time that the actual Copyright information about a Layer will replace the placeholder text that is shown in the Attribution Control defined at design-time. The following image shows the run-time display of the Map Control and the Attribution Control that corresponds to the previous design-time screen shot where the actual Copyright information about the Layers is displayed.

Example of the visual appearance of the Attribution Control at run-time when the Attribution.Layers Property is bound to the Map.Layers Property.

Note: Setting the Layer.ID Property is typically done in XAML or in code-behind. The Layer.ID is usually not populated in the map service.

If length of the Copyright information string for a Layer exceeds the Attribution Controls Width, the text will wrap across multiple lines to avoid truncation.

Example

How to use:

By default two Layers have been added to the Map Control and the Copyright information for those Layers are displayed in the Attribution Control. Click the 'Add Layer Dynamically' button to add another Layer to the Map and see the newly added Copyright information added to the Attribution Control.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Visual example of the Attribution Control displaying CopyrightText information about various layers.

XAMLCopy Code
<Grid x:Name="LayoutRoot">
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="65" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="626" 
             TextWrapping="Wrap" Margin="2,2,0,0" 
             Text="By default two Layers have been added to the Map Control and the Copyright information
             for those Layers are displayed in the Attribution Control. Click the 'Add Layer Dynamically' 
             button to add another Layer to the Map and see the newly added Copyright information
             added to the Attribution Control." />
  
  <!-- Add a Map Control zoomed to a specific Extent. -->  
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="12,102,0,0" Name="Map1" 
            VerticalAlignment="Top" Height="306" Width="545" 
            Extent="-10723833,4627392,-10704398,4644168">
  
    <!-- 
    Add an ArcGISTiledMapServiceLayer. Note: No ID value was specified and hence the Layer can not
    be accessed via code-behind. Also, since no ID value was specified the design-time will list the
    Type of Layer in Attribution Control placeholder (Ex: ArcGISTiledMapServiceLayer attribution.).
    -->
    <esri:ArcGISTiledMapServiceLayer  
          Url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/>
    
    <!-- 
    Add an ArcGISDynamicMapServiceLayer. Note: since an ID value is specified the design-time will 
    list the Layer ID in Attribution Control placeholder (Ex: World Transportation attribution.).
    -->
    <esri:ArcGISDynamicMapServiceLayer ID="World Transportation"
          Url="http://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer" />
    
  </esri:Map>
  
  <!--
  Add an Attribution Control and Bind the Map.Layers to the Attribution.Layers. Change a few
  visual appearance settings related to the Font for the text that is displayed in the Control. 
  -->
  <esri:Attribution HorizontalAlignment="Left" Margin="12,420,0,0" Name="Attribution1" 
                    VerticalAlignment="Top" Layers="{Binding ElementName=Map1,Path=Layers}" 
                    Width="545" Height="48" 
                    FontSize="11" FontFamily="Arial" Foreground="Chocolate"/>
     
  <!-- 
  Add a button to dynamically add a Layer to the Map which will also automatically update what is in
  the Attribution Control. Note the Click event handler is wired up to use code-behind. 
  -->
  <Button Content="Add Layer Dynamically" Height="23" HorizontalAlignment="Left" Margin="12,73,0,0" 
          Name="AddLayerDynamically" VerticalAlignment="Top" Width="545" Click="AddLayerDynamically_Click"/>
  
</Grid>
C#Copy Code
private void AddLayerDynamically_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // This function dynamically (i.e. at run-time) adds a FeatureLayer to the Map Control. As a result the 
  // Attribution Control will also be updated with the CopyrightText information available on the Layer.
  
  // Create a new FeatureLayer and set a few Properties. 
  ESRI.ArcGIS.Client.FeatureLayer myFeatureLayer = new ESRI.ArcGIS.Client.FeatureLayer();
  myFeatureLayer.Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/FeatureServer/1";
  myFeatureLayer.DisableClientCaching = true;
  myFeatureLayer.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.OnDemand;
  
  // Add the FeatureLayer to the Map Control.
  Map1.Layers.Add(myFeatureLayer);
}
VB.NETCopy Code
Private Sub AddLayerDynamically_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
  
  ' This function dynamically (i.e. at run-time) adds a FeatureLayer to the Map Control. As a result the 
  ' Attribution Control will also be updated with the CopyrightText information available on the Layer.
  
  ' Create a new FeatureLayer and set a few Properties. 
  Dim myFeatureLayer As New ESRI.ArcGIS.Client.FeatureLayer
  myFeatureLayer.Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/FeatureServer/1"
  myFeatureLayer.DisableClientCaching = True
  myFeatureLayer.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.OnDemand
  
  ' Add the FeatureLayer to the Map Control.
  Map1.Layers.Add(myFeatureLayer)
  
End Sub

Inheritance Hierarchy

System.Object
   System.Windows.DependencyObject
      System.Windows.UIElement
         System.Windows.FrameworkElement
            System.Windows.Controls.Control
               ESRI.ArcGIS.Client.Toolkit.Attribution

Requirements

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

See Also

© ESRI, Inc. All Rights Reserved.