Select to view content in your preferred language

Hyperlinking Support for FeatureDataGrid in Silverlight

1117
9
12-06-2010 08:45 AM
JoshShelton
Occasional Contributor
Hello!

I am an absolute rookie at developing with silverlight and ESRI's Silverlight API (pretty much developing in general!), and I am trying to teach myself how to do all of this... That said, I found the below xaml code from this post regarding hyperlinking support in FeatureDataGrids and I am trying to implement it into my project.

http://forums.arcgis.com/threads/10338-Adding-Hyperlink-Support-to-the-FeatureDataGrid-in-Silverligh...

xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"


<esri:FeatureDataGrid x:Name="MyFeatureDataGrid" Height="240" VerticalAlignment="Bottom" AutoGenerateColumns="False" 
         Map="{Binding ElementName=MyMap}" GraphicsLayer="{Binding Layers[1], ElementName=MyMap}">
   <esri:FeatureDataGrid.Columns>
    <data:DataGridTextColumn Binding="{Binding type}" Header="Type" />
    <data:DataGridTemplateColumn Header="Description">
     <data:DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
       <HyperlinkButton Content="{Binding description}" NavigateUri="{Binding description}" TargetName="_blank" />
      </DataTemplate>
     </data:DataGridTemplateColumn.CellTemplate>
    </data:DataGridTemplateColumn>
   </esri:FeatureDataGrid.Columns>
  </esri:FeatureDataGrid>


Can someone please help me to configure this code snippet for use in my project? I have a map service called BaseMap containing a layer called URL. Inside the layer I want to pull across 2 fields. One is called [pno_1] the other [URL] (this field contains the linking information). I think my issue here is with the binding... Again, I am trying to teach myself how to do all of this so please be gentle!

Thank you in advance for your help. Josh.
0 Kudos
9 Replies
JenniferNery
Esri Regular Contributor
If you are working on SL4, post #6 on this thread answers your question 🙂
http://forums.arcgis.com/threads/7374-Binding-to-Hyperlink-NavigateURI-property.

Also, to clarify the Binding statement. The DataContext for FeatureDataGrid is the graphic Attributes which is of type IDictionary<string, object>. You need to access this dictionary to get the value. Instead of "{Binding description}" you need to surround the key with accessor (square) brackets "{Binding [description]}".
0 Kudos
JoshShelton
Occasional Contributor
Thank you for your reply!

I will give this a try. However, I have the entire path in my field called URL that I would like to use. Should I split this and use the StringFormat as the base of the URL and then define a field with the information to append to the URL string?

I am using SL4 and VB. Thank you again for your help.
0 Kudos
JenniferNery
Esri Regular Contributor
Oh. If your attribute already contains the entire path, then you don't need to use StringFormat. This was only an example if you needed to search google for an attribute name. Sorry I did not make that clear 😛
0 Kudos
JoshShelton
Occasional Contributor
I apologize for the confusion.

I think this brings me back to my initial question. How can I configure the xaml code I initially posted (if I can configure it to do this) to pull the entire URL from my attributes to be used as the hyperlink in the FeatureDataGrid? My ultimate goal is to have it pull the path information from the attributes and have the user click on it as a hyperlink...

Thanks again!
0 Kudos
JenniferNery
Esri Regular Contributor
If you say that the attribute already contains the full URL and the value is of type Uri, then you were on the right track, just include square brackets:
 
   <HyperlinkButton Content="{Binding [description]}" NavigateUri="{Binding [description]}" TargetName="_blank" />
0 Kudos
JoshShelton
Occasional Contributor
Do I replace 'description' within the brackets with the name of my layer? Ex: [MyLayer]

Also, for this peice of the code, what is supposed to replace type in {Binding type}?

<data:DataGridTextColumn Binding="{Binding type}" Header="Type" />


Thanks again, and I aplogize for my ignorance!
0 Kudos
JenniferNery
Esri Regular Contributor
Oh no worries, these are good questions. Both 'type' and 'description' are assumed to be fields in your feature service, which we have also been referring to as attributes of your graphics.

The code you posted must then be meant for a specific feature service? If yes, you need to replace them with the actual fields of your service. You can visit the FeatureLayer URL directly from your web browser to see more information about the layer.
0 Kudos
JoshShelton
Occasional Contributor
I am using a DynamicMapServiceLayer, will this still work or does it need to be a FeatureService?

The name of the service is BaseMap, and the field with the paths for the hyperlink is URL. How do I know if the values in my field ore of type Uri?

Thanks.
0 Kudos
JenniferNery
Esri Regular Contributor
FeatureDataGrid works with a single layer on your map service or feature service.
For example: http://serverapps.esri.com/ArcGIS/rest/services/California/MapServer/8
instead of http://serverapps.esri.com/ArcGIS/rest/services/California/MapServer.

You can see that each layer have different fields/attributes.

This may be related to what you are trying to accomplish: http://forums.arcgis.com/threads/8309-How-to-perform-spatial-query-between-two-services...

Since the attributes/fields will be unknown until user selects a layer, you can use GraphicsLayer for your FeatureDataGrid. Perform a QueryTask on selected service. And store the results to this GraphicsLayer.

This also means you need to create your columns in code or have different DataTemplate resource per layer and set the column template in code-behind or allow AutoGenerateColumns.
0 Kudos