private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args) { IdentifyDetailsDataGrid.ItemsSource = null; if (args.IdentifyResults != null && args.IdentifyResults.Count > 0) { IdentifyResultsPanel.Visibility = Visibility.Visible; IdentifyDataForm2.DataContext = args.IdentifyResults.Feature.Attributes ; ShowFeatures(args.IdentifyResults); } else { IdentifyComboBox.Items.Clear(); IdentifyComboBox.UpdateLayout(); IdentifyResultsPanel.Visibility = Visibility.Collapsed; } }
IdentifyDataForm2.ItemsSource = feature.Attributes;but the attribute data appears as a list of name/value pairs and so the dataform only displays the first pair. Is there a way to get the all the attributes together so they will all show in the dataform?
<StackPanel Orientation="Horizontal"> <TextBlock Text="State Name: "/> <TextBlock Text="{Binding [STATE_NAME]}"/> </StackPanel>
This sample http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify assumes that the IdentifyComboBox will contain titles and IdentifyDetailsDataGrid will contain the feature attributes. This sample uses DataItem class to update the IdentifyDetailsDataGrid source on IdentifyComboBox SelectionChanged event.
You need to update the XAML-code for IdentifyDetailsDataGrid and replace it with your own data form. You also need to know which layer the feature belongs to in order to know the fields you need for Binding.
For example:<StackPanel Orientation="Horizontal"> <TextBlock Text="State Name: "/> <TextBlock Text="{Binding [STATE_NAME]}"/> </StackPanel>
<toolkit:DataForm x:Name="IdentifyDataForm2" AutoGenerateFields="False" IsReadOnly="True" IsEnabled="True" LabelPosition="Left" Height="150" VerticalAlignment="Top"> <StackPanel Orientation="Horizontal"> <TextBlock Text="Name: "/> <TextBlock Text="{Binding [ST_NAME]}"/> </StackPanel> </toolkit:DataForm>
void cb_SelectionChanged(object sender, SelectionChangedEventArgs e) { int index = IdentifyComboBox.SelectedIndex; if (index > -1) IdentifyDetailsDataGrid.ItemsSource = _dataItems[index].Data; IdentifyDataForm2.ItemsSource = _dataItems[index].Data ; //////////////////////////////// }Note both controls are looking at the same data. However while the datagrid displays properly, the dataform displays only the textblock containing the label and not the one containing the data.
<StackPanel x:Name="MyDataForm" VerticalAlignment="Top" HorizontalAlignment="Center" Orientation="Horizontal"> <TextBlock Text="State Name: "/> <TextBlock Text="{Binding [STATE_NAME]}"/> </StackPanel>
void cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = IdentifyComboBox.SelectedIndex;
if (index > -1)
{
IdentifyDetailsDataGrid.ItemsSource = _dataItems[index].Data;
MyDataForm.DataContext = _dataItems[index].Data;
}
}
Have you looked at this SL4 Toolkit sample? http://www.silverlight.net/content/samples/sl4/toolkitcontrolsamples/run/default.html. Look at the Template-Driven sample. I think you need to define template for each layer since they will have different fields.
A simpler example will be this. Add the following XAML-code to the Identify SDK sample:
<StackPanel x:Name="MyDataForm" VerticalAlignment="Top" HorizontalAlignment="Center" Orientation="Horizontal"> <TextBlock Text="State Name: "/> <TextBlock Text="{Binding [STATE_NAME]}"/> </StackPanel>
In code-behind, set its DataContext when DataGrid gets its ItemsSource.
void cb_SelectionChanged(object sender, SelectionChangedEventArgs e) { int index = IdentifyComboBox.SelectedIndex; if (index > -1) { IdentifyDetailsDataGrid.ItemsSource = _dataItems[index].Data; MyDataForm.DataContext = _dataItems[index].Data; } }