ArcGIS Runtime SDK for WPF - Library Reference
GraphicSource Property
See Also  Example
ESRI.ArcGIS.Client.Toolkit Namespace > AttachmentEditor Class : GraphicSource Property

Gets or sets the Graphic source of the FeatureLayer for the AttachmentEditor.

Syntax

Visual Basic (Declaration) 
Public Property GraphicSource As Graphic
C# 
public Graphic GraphicSource {get; set;}

Remarks

It is the AttachmentEditor.GraphicSource Property that causes the AttachmentEditor to make a call to the ArcGIS Server FeatureServer to see if any existing attachments are associated with a specific Graphic in the FeatureLayer stored in the backend database. If any attachments are found to be associated with a Graphic in the FeatureLayer, they will be listed in the ListBox portion of the control. For each attachment that is listed in the ListBox of the AttachmentEditor, users can click on the hyperlink with the attachment filename to use the Microsoft File Download dialog to save the file on the local machine. Attachments listed in the ListBox can also be deleted from the backend ArcGIS Server FeatureService by clicking the red X next to the attachment name. When a Graphic is associated with the AttachmentEditor.GraphicSource Property the Add button of the AttachmentEditor becomes enabled. The Add button allows users on the client machine to upload files on the local computer to the ArcGIS Server FeatureServer backend database via the Microsoft OpenFileDialog dialog.

Obtaining a Graphic feature from the FeatureLayer to be used as the AttachmentEditor.GraphicSource is typically obtained by a Property on the FeatureLayer such as:

or via an Event on the FeatureLayer such as:

Example

How to use:

This sample code shows setting the AttachmentEditor.GraphicSource two different ways. One way uses the ESRI.ArcGIS.Client.GraphicMouseButtonEventArgs input argument of the FeatureLayer.MouseLeftButtonUp Event to attach the Graphic to the AttachmentEditor.GraphicSource. The other way obtains the Graphic by iterating over the GraphicCollection from a user choice of selecting the objectid value in a ListBox to set the AttachmentEditor.GraphicSource:

  1. Click on the Map to select a Graphic and add a few Attachments using the AttachmentEditor Control. Repeat this step for several Graphics.
  2. Then Click the 'Load the objectid of Graphic with Attachments in the ListBox' button to list all of the Graphic 'objectid' values that have Attachments in the ListBox for all Graphics in the current Map's Extent.
  3. Finally, Click on the 'objectid' string in the ListBox and the associated Graphic will be selected in the Map and will automatically display it's Attachment information in the AttachmentEditor 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.

Demonstrating setting the AttachmentEditor.GraphicSource using two alternative ways.

XAMLCopy Code
<Grid x:Name="LayoutRoot">
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="189" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" 
         Width="760" TextWrapping="Wrap" Margin="12,12,0,0" 
         Text="This sample code shows setting the AttachmentEditor.GraphicSource two different ways. One way uses 
         the ESRI.ArcGIS.Client.GraphicMouseButtonEventArgs input argument of the FeatureLayer.MouseLeftButtonUp 
         Event to attach the Graphic to the AttachmentEditor.GraphicSource. The other way obtains the Graphic by 
         iterating over the GraphicCollection from a user choice of selecting the objectid value in a ListBox to 
         set the AttachmentEditor.GraphicSource:
         1. Click on the Map to select a Graphic and add a few Attachments using the AttachmentEditor Control. 
         Repeat this step for several Graphics.
         2. Then Click the 'Load the objectid of Graphic with Attachments in the ListBox' button to list all of 
         the Graphic 'objectid' values that have Attachments in the ListBox for all Graphics in the current 
         Map's Extent.
         3. Finally, Click on the 'objectid' string in the ListBox and the associated Graphic will be selected in 
         the Map and will automatically display it's Attachment information in the AttachmentEditor Control." />
         
  <!-- 
  Add a Map control with an ArcGISTiledMapeServiceLayer and a FeatureLayer. It is important to 
  provide a Name for the Map Control as this will be used by the AttachmentEditor Control.
  Define and initial Extent for the map.
  -->
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="12,225,0,0" Name="MyMap" 
          VerticalAlignment="Top" Height="375" Width="418" 
            Extent="-13629929,4545159,-13627707,4547153">
  
    <!-- Add a backdrop ArcGISTiledMapServiceLayer. -->
    <esri:ArcGISTiledMapServiceLayer 
              Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
    
    <!-- 
    The FeatureLayer is based upon an ArcGIS Server 'FeatureServer' service not a 'MapServer' service.
    It is important to provide an ID value as this will be used for Binding in the AttachementEditor.
    The MouseLeftButtonUp Event handler has been defined for the FeatureLayer. In order to improve
    performance of the example code a Where clause was used to restrict the amount of Graphic features
    returned from the FeatureLayer FeatureService. Setting the Mode Property equal to OnDemand also 
    helps to improve performance by further restricting the returned Graphc features to only those that
    are visible in the current Map.Extent.
    -->
    <esri:FeatureLayer ID="IncidentsLayer"
           Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0"
           MouseLeftButtonUp="FeatureLayer_MouseLeftButtonUp" AutoSave="False"                  
           DisableClientCaching="True" OutFields="*" Mode="OnDemand" 
           Where="district = '8' AND req_type = 'Damaged Property'"/>
    
  </esri:Map>
  
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="440,207,0,0" Name="Label2" 
             VerticalAlignment="Top" Width="290" Content="The Attachment Editor:"/>
  
  <!--
  Add an AttachmentEditor. Provide a x:Name for the AttachmentEditor so that it can be used in the 
  code-behind file. The FeatureLayer Property is bound to the 'IncidentLayer' of the Map Control.
  Only one group of Filter types are used (you can have multiple file extensions in a group) to drive 
  the OpenFileDialog. This AttachmentEditor will only allow the uploading of Image files. The 
  FilterIndex shows the first group of Filter Types in the OpenFileDialog dropdown list. Only allow 
  the user to upload (i.e. Add) one file at a time using the OpenFileDialog with the Multiselect set 
  to False. 
  -->
  <esri:AttachmentEditor x:Name="MyAttachmentEditor" VerticalAlignment="Top" Margin="436,225,0,0" 
                           Background="LightGoldenrodYellow" Width="352" Height="110" HorizontalAlignment="Left"                              
                           FeatureLayer="{Binding Layers[IncidentsLayer], ElementName=MyMap}" 
                           Filter="Image Files|*.jpg;*.gif;*.png;*.bmp" 
                           FilterIndex="1" Multiselect="False">
  </esri:AttachmentEditor>
  
  <!-- 
  Add a Button to perform the work of looping through all of the Graphics in the current Map.Extent, 
  obtaining which Graphics have associated Attachments, and display the 'objectid' values of those
  Graphics in the ListBox. The Click Event handler is wired up for use in the code-behind. 
  -->
  <Button  Content="Load the objectid of Graphic with Attachments in the ListBox" Height="35" 
          HorizontalAlignment="Left" Margin="436,361,0,0" Name="Button1" 
          VerticalAlignment="Top" Width="352" Click="Button1_Click" >
  </Button>
  
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="436,419,0,0" Name="Label1" 
             VerticalAlignment="Top" Width="336"
             Content="Graphics object in the Map with Attachments:"/>
  
  <!--
  Add a ListBox to display any Graphic 'objectid' values in the current Map.Extent that have
  Attachments associated with them. If no Graphic features in the current Map.Extent have 
  Attachments nothing will be displayed. You may need to add some Attachments to the Graphics
  in order to see the full functionality of the example code. The SelectionChanged Event handler
  is wired up for use in the code-behind.
  -->
  <ListBox Height="145" HorizontalAlignment="Left" Margin="436,443,0,0" Name="ListBox1" 
           VerticalAlignment="Top" Width="352"
           SelectionChanged="ListBox1_SelectionChanged" />
  
</Grid>
C#Copy Code
// The purpose of this example code is to show that the AttachmentEditor.GraphicSource can be set a few
// different ways: 
// (1) via user interaction with the Map 
// (2) via user interaction with non-Map controls
// The important thing to learn is that a valid Graphic needs to be set for the 
// AttachmentEditor.GraphicSource, irrespective of how it is obtained.
  
private void ListBox1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
  // This function loops through all of the Graphics in the FeatureLayer and unselects them. Then
  // for the 'objectid' value that was selected in the ListBox, select it to show visually on the
  // Map and set the AttachmentEditor.GraphicSource Property.
  
  // Get the FeatureLayer from the XAML.
  ESRI.ArcGIS.Client.FeatureLayer myFeatureLayer = (ESRI.ArcGIS.Client.FeatureLayer)MyMap.Layers["IncidentsLayer"];
  
  // Loop through all of the Graphics in the FeatureLayer and UnSelect them.
  for (int i = 0; i < myFeatureLayer.SelectionCount; i++)
  {
    myFeatureLayer.SelectedGraphics.ToList()[i].UnSelect();
  }
  
  // Obtain the GraphicsCollection from the FeatureLayer.
  ESRI.ArcGIS.Client.GraphicCollection myGraphicCollection = myFeatureLayer.Graphics;
  
  // Another way to loop through all of the Graphics. 
  foreach (ESRI.ArcGIS.Client.Graphic myGraphic in myGraphicCollection)
  {
    // This time find the specific Graphic that has a matching 'objectid' value as chosen by 
    // the user in the ListBox, select it for visual display in the Map and set the 
    // AttachmentEditor.GraphicSource Property.
    String myString = myGraphic.Attributes["objectid"].ToString();
    if (myString == (ListBox1.SelectedItem.ToString()))
    {
      myGraphic.Select();
      MyAttachmentEditor.GraphicSource = myGraphic;
      break;
    }
  }
}
  
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // This function scans through all of the Graphics of the FeatureLayer in the current Map.Extent
  // and uses an Action Delegate to perform a FeatureLayer.QueryAttachmentInfos Method call to list
  // all of the Graphic 'objectid' values in a ListBox for with there are associated Attachments.
  
  // Clear out the ListBox for multiple runs
  ListBox1.Items.Clear();
  
  // Get the FeatureLayer that was defined in XAML.
  ESRI.ArcGIS.Client.FeatureLayer myFeatureLayer = (ESRI.ArcGIS.Client.FeatureLayer)MyMap.Layers["IncidentsLayer"];
  
  // Get the GraphicCollection from the FeatureLayer
  ESRI.ArcGIS.Client.GraphicCollection myGraphicCollection = myFeatureLayer.Graphics;
  
  // Loop through each Graphic in the GraphicCollection
  foreach (ESRI.ArcGIS.Client.Graphic myGraphic in myGraphicCollection)
  {
    // Define the Action Delegate
    Action<System.Collections.Generic.IEnumerable<ESRI.ArcGIS.Client.FeatureService.AttachmentInfo>> myAction = null;
    myAction = PopulateTheListBoxWith_objectid_Values;
    
    // Use the FeatureLayer.QueryAttachmentInfos Method to call the PopulateTheListBoxWith_objectid_Values
    // Function.
    // SPECIAL NOTE: 
    // By using an Action Delegate, the processing of the request does not occur until this Button1_Click
    // Function has completely finished processing (this means the For/Each loop will completely process 
    // BEFORE any calls to the PopulateTheListBoxWith_objectid_Values Function begin). Set some breakpoints
    // to see how this operation occurs. As a result of the 'queuing up' of all the 
    // PopulateTheListBoxWith_objectid_Values Function calls, there is no way to know exactly when the 
    // PopulateTheListBoxWith_objectid_Values Function calls are going to finish processing since they 
    // do not fire sequentially from within the For/Each loop. 
    myFeatureLayer.QueryAttachmentInfos(myGraphic, myAction, null);
  }
}
            
public void PopulateTheListBoxWith_objectid_Values(System.Collections.Generic.IEnumerable<ESRI.ArcGIS.Client.FeatureService.AttachmentInfo> myAttachmentsInfos)
{
  // This function gets called as a result of an Action Delegate. An 
  // IEnumerable(Of ESRI.ArcGIS.Client.FeatureService.AttachmentInfo) objects are available to be 
  // interrogated. If there is a valid AttachmentInfo object use the .Split String operation on
  // the AttachmentInfo.Uri Property to extract out the 'objectid' value of the Graphic in the 
  // FeatureLayer. For more information on the specific Uri structure see the ArcGIS Server REST 
  // API document called "Attachment - Feature Service":
  // http://sampleserver3.arcgisonline.com/ArcGIS/SDK/REST/fsattachment.html
  // Once the 'objectid' value is obtained, add it to the ListBox so that users can click on it
  // to highlight the Graphic feature in the Map and set the AttachmentEditor.GraphicSource Property.
  
  // Example of information of an AttachmentsInfo object:
  // ContentType = "image/jpeg"
  // Delete = {ESRI.ArCGIS.Client.DelegateCommand}
  // ID = 467
  // Name = "Chrysanthemum.jpg"
  // Size = 87396
  // Uri = {http://sampleserver3/arcgisonline/com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0/121979/attachments/467}
  
  // Loop through the IEnumerable(Of ESRI.ArcGIS.Client.FeatureService.AttachmentInfo) objects
  foreach (ESRI.ArcGIS.Client.FeatureService.AttachmentInfo oneAttchmentInfo in myAttachmentsInfos)
  {
    // Tokenize the AttachmentInfo.Uri value into an array of String objects.
    string[] parts = oneAttchmentInfo.Uri.ToString().Split('/');
    
    // Get the 'objectid' value for a Graphic Feature from the AttachmentInfo.Uri.
    string my_objectid = parts[parts.Length - 3].ToString();
    
    // Only add unique occurrences of the 'objectid' value to the ListBox. There could me
    // multiple attachments per Graphic Feature.
    if (!(ListBox1.Items.Contains(my_objectid)))
    {
      ListBox1.Items.Add(my_objectid);
    }
  }
}
            
private void FeatureLayer_MouseLeftButtonUp(object sender, ESRI.ArcGIS.Client.GraphicMouseButtonEventArgs e)
{
  // This function obtains the FeatureLayer, loops through all of the Graphic features and
  // un-selects them. Then for the Graphic for which the user clicked with the mouse select
  // it and use that Graphic to set the AttachmentEditor.GraphicSource to enable uploading,
  // downloading, and deleting attachment files on the ArcGIS Server backend database.
  
  // Get the FeatureLayer from the sender object of the FeatureLayer.MouseLeftButtonUp Event.
  ESRI.ArcGIS.Client.FeatureLayer myFeatureLayer = sender as ESRI.ArcGIS.Client.FeatureLayer;
  
  // Loop through all of the Graphics in the FeatureLayer and UnSelect them.
  for (int i = 0; i < myFeatureLayer.SelectionCount; i++)
  {
    myFeatureLayer.SelectedGraphics.ToList()[i].UnSelect();
  }
  
  // Select the Graphic from the e object which will change visibly on the Map via highlighting.
  e.Graphic.Select();
  
  // Setting the AttachmentEditor.GraphicSource immediately causes the AttachmentEditor Control 
  // to update with any attachments currently associated with the Graphic.
  MyAttachmentEditor.GraphicSource = e.Graphic;
}
VB.NETCopy Code
' The purpose of this example code is to show that the AttachmentEditor.GraphicSource can be set a few
' different ways: 
' (1) via user interaction with the Map 
' (2) via user interaction with non-Map controls
' The important thing to learn is that a valid Graphic needs to be set for the 
' AttachmentEditor.GraphicSource, irrespective of how it is obtained.
            
Private Sub ListBox1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
  
  ' This function loops through all of the Graphics in the FeatureLayer and unselects them. Then
  ' for the 'objectid' value that was selected in the ListBox, select it to show visually on the
  ' Map and set the AttachmentEditor.GraphicSource Property.
  
  ' Get the FeatureLayer from the XAML.
  Dim myFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = MyMap.Layers("IncidentsLayer")
  
  ' Loop through all of the Graphics in the FeatureLayer and UnSelect them.
  For i As Integer = 0 To myFeatureLayer.SelectionCount - 1
    myFeatureLayer.SelectedGraphics.ToList()(i).UnSelect()
  Next i
  
  ' Obtain the GraphicsCollection from the FeatureLayer.
  Dim myGraphicCollection As ESRI.ArcGIS.Client.GraphicCollection = myFeatureLayer.Graphics
  
  ' Another way to loop through all of the Graphics. 
  For Each myGraphic As ESRI.ArcGIS.Client.Graphic In myGraphicCollection
    
    ' This time find the specific Graphic that has a matching 'objectid' value as chosen by 
    ' the user in the ListBox, select it for visual display in the Map and set the 
    ' AttachmentEditor.GraphicSource Property.
    If myGraphic.Attributes.Item("objectid") = ListBox1.SelectedItem.ToString Then
      myGraphic.Select()
      MyAttachmentEditor.GraphicSource = myGraphic
      Exit For
    End If
  Next
  
End Sub
            
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
  
  ' This function scans through all of the Graphics of the FeatureLayer in the current Map.Extent
  ' and uses an Action Delegate to perform a FeatureLayer.QueryAttachmentInfos Method call to list
  ' all of the Graphic 'objectid' values in a ListBox for with there are associated Attachments.
  
  ' Clear out the ListBox for multiple runs
  ListBox1.Items.Clear()
  
  ' Get the FeatureLayer that was defined in XAML.
  Dim myFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = MyMap.Layers("IncidentsLayer")
  
  ' Get the GraphicCollection from the FeatureLayer
  Dim myGraphicCollection As ESRI.ArcGIS.Client.GraphicCollection = myFeatureLayer.Graphics
  
  ' Loop through each Graphic in the GraphicCollection
  For Each myGraphic As ESRI.ArcGIS.Client.Graphic In myGraphicCollection
    
    ' Define the Action Delegate
    Dim myAction As Action(Of System.Collections.Generic.IEnumerable(Of ESRI.ArcGIS.Client.FeatureService.AttachmentInfo))
    myAction = AddressOf PopulateTheListBoxWith_objectid_Values
    
    ' Use the FeatureLayer.QueryAttachmentInfos Method to call the PopulateTheListBoxWith_objectid_Values
    ' Function.
    ' SPECIAL NOTE: 
    ' By using an Action Delegate, the processing of the request does not occur until this Button1_Click
    ' Function has completely finished processing (this means the For/Each loop will completely process 
    ' BEFORE any calls to the PopulateTheListBoxWith_objectid_Values Function begin). Set some breakpoints
    ' to see how this operation occurs. As a result of the 'queuing up' of all the 
    ' PopulateTheListBoxWith_objectid_Values Function calls, there is no way to know exactly when the 
    ' PopulateTheListBoxWith_objectid_Values Functoion calls are going to finish processing since they 
    ' do not fire sequentially from within the For/Each loop. 
    myFeatureLayer.QueryAttachmentInfos(myGraphic, myAction, Nothing)
    
  Next
  
End Sub
            
Public Sub PopulateTheListBoxWith_objectid_Values(ByVal myAttachmentsInfos As System.Collections.Generic.IEnumerable(Of ESRI.ArcGIS.Client.FeatureService.AttachmentInfo))
  
  ' This function gets called as a result of an Action Delegate. An 
  ' IEnumerable(Of ESRI.ArcGIS.Client.FeatureService.AttachmentInfo) objects are available to be 
  ' interrogated. If there is a valid AttachmentInfo object use the .Split String operation on
  ' the AttachmentInfo.Uri Property to extract out the 'objectid' value of the Graphic in the 
  ' FeatureLayer. For more information on the specific Uri structure see the ArcGIS Server REST 
  ' API document called "Attachment - Feature Service":
  ' http://sampleserver3.arcgisonline.com/ArcGIS/SDK/REST/fsattachment.html
  ' Once the 'objectid' value is obtained, add it to the ListBox so that users can click on it
  ' to highlight the Graphic feature in the Map and set the AttachmentEditor.GraphicSource Property.
  
  ' Example of information of an AttachmentsInfo object:
  ' ContentType = "image/jpeg"
  ' Delete = {ESRI.ArCGIS.Client.DelegateCommand}
  ' ID = 467
  ' Name = "Chrysanthemum.jpg"
  ' Size = 87396
  ' Uri = {http://sampleserver3/arcgisonline/com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0/121979/attachments/467}
  
  ' Loop through the IEnumerable(Of ESRI.ArcGIS.Client.FeatureService.AttachmentInfo) objects
  Dim oneAttchmentInfo As ESRI.ArcGIS.Client.FeatureService.AttachmentInfo
  For Each oneAttchmentInfo In myAttachmentsInfos
    
    ' Tokenize the AttachmentInfo.Uri value into an array of String objects.
    Dim parts As String() = oneAttchmentInfo.Uri.ToString.Split("/")
    
    ' Get the 'objectid' value for a Graphic Feature from the AttachmentInfo.Uri.
    Dim my_objectid As String = parts(parts.Length - 3).ToString
    
    ' Only add unique occurrences of the 'objectid' value to the ListBox. There could me
    ' multiple attachments per Graphic Feature.
    If Not ListBox1.Items.Contains(my_objectid) Then
      ListBox1.Items.Add(my_objectid)
    End If
  Next
  
End Sub
            
Private Sub FeatureLayer_MouseLeftButtonUp(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Client.GraphicMouseButtonEventArgs)
  
  ' This function obtains the FeatureLayer, loops through all of the Graphic features and
  ' un-selects them. Then for the Graphic for which the user clicked with the mouse select
  ' it and use that Graphic to set the AttachmentEditor.GraphicSource to enable uploading,
  ' downloading, and deleting attachment files on the ArcGIS Server backend database.
  
  ' Get the FeatureLayer from the sender object of the FeatureLayer.MouseLeftButtonUp Event.
  Dim myFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = TryCast(sender, ESRI.ArcGIS.Client.FeatureLayer)
  
  ' Loop through all of the Graphics in the FeatureLayer and UnSelect them.
  For i As Integer = 0 To myFeatureLayer.SelectionCount - 1
    myFeatureLayer.SelectedGraphics.ToList()(i).UnSelect()
  Next i
  
  ' Select the Graphic from the e object which will change visibly on the Map via highlighting.
  e.Graphic.Select()
            
  ' Setting the AttachmentEditor.GraphicSource immediately causes the AttachmentEditor Control 
  ' to update with any attachments currently associated with the Graphic.
  MyAttachmentEditor.GraphicSource = e.Graphic
            
End Sub

Requirements

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

See Also

© ESRI, Inc. All Rights Reserved.