Solved! Go to Solution.
<StackPanel> <slData:DataGrid x:Name="IdentifyDetailsDataGrid" AutoGenerateColumns="False" HeadersVisibility="None" Background="White"> <slData:DataGrid.Columns> <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/> <slData:DataGridTextColumn Binding="{Binding Path=Value}"/> </slData:DataGrid.Columns> </slData:DataGrid> <slData:DataGrid x:Name="IdentifyDetailsDataGrid2" AutoGenerateColumns="False" HeadersVisibility="None" Background="White"> <slData:DataGrid.Columns> <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/> <slData:DataGridTextColumn Binding="{Binding Path=Value}"/> </slData:DataGrid.Columns> </slData:DataGrid> </StackPanel> public void ShowFeatures(List<IdentifyResult> results) { _dataItems = new List<DataItem>(); if (results != null && results.Count > 0) { IdentifyComboBox.Items.Clear(); foreach (IdentifyResult result in results) { Graphic feature = result.Feature; string title = result.Value.ToString() + " (" + result.LayerName + ")"; _dataItems.Add(new DataItem() { Title = title, Data = feature.Attributes }); IdentifyComboBox.Items.Add(title); if(result.LayerId == 3) IdentifyDetailsDataGrid.ItemsSource = feature.Attributes; else IdentifyDetailsDataGrid2.ItemsSource = feature.Attributes; } IdentifyComboBox.SelectedIndex = 0; } }
if (e.IdentifyResults.Any(r => r.LayerId == 1))
{
var resultsFrom1 = e.IdentifyResults.Where(r => r.LayerId == 1);
displayComboBoxFrom1.ItemsSource = resultsFrom1;
}
if (e.IdentifyResults.Any(r => r.LayerId == 2))
{
var resultsFrom2 = e.IdentifyResults.Where(r => r.LayerId == 2);
displayComboBoxFrom2.ItemsSource = resultsFrom2;
}
if (args.IdentifyResults.Count > 0)
{
IdentifyResultsStackPanel.Visibility = Visibility.Visible;
foreach (IdentifyResult result in args.IdentifyResults)
{
string title = string.Format("{0} ({1})", result.Value.ToString(), result.LayerName);
IdentifyComboBox.Items.Add(title);
}
<StackPanel> <slData:DataGrid x:Name="IdentifyDetailsDataGrid" AutoGenerateColumns="False" HeadersVisibility="None" Background="White"> <slData:DataGrid.Columns> <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/> <slData:DataGridTextColumn Binding="{Binding Path=Value}"/> </slData:DataGrid.Columns> </slData:DataGrid> <slData:DataGrid x:Name="IdentifyDetailsDataGrid2" AutoGenerateColumns="False" HeadersVisibility="None" Background="White"> <slData:DataGrid.Columns> <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/> <slData:DataGridTextColumn Binding="{Binding Path=Value}"/> </slData:DataGrid.Columns> </slData:DataGrid> </StackPanel> public void ShowFeatures(List<IdentifyResult> results) { _dataItems = new List<DataItem>(); if (results != null && results.Count > 0) { IdentifyComboBox.Items.Clear(); foreach (IdentifyResult result in results) { Graphic feature = result.Feature; string title = result.Value.ToString() + " (" + result.LayerName + ")"; _dataItems.Add(new DataItem() { Title = title, Data = feature.Attributes }); IdentifyComboBox.Items.Add(title); if(result.LayerId == 3) IdentifyDetailsDataGrid.ItemsSource = feature.Attributes; else IdentifyDetailsDataGrid2.ItemsSource = feature.Attributes; } IdentifyComboBox.SelectedIndex = 0; } } <!--IDENTIFY TASK INTERFACE-->
<StackPanel Margin="10" HorizontalAlignment="Right">
<Grid>
<Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" Margin="0,0,0,-25" />
<TextBlock Text="School Attendance Area:" Foreground="White" FontSize="10"
Margin="14,9,6,6" />
<StackPanel x:Name="IdentifyResultsStackPanel" Margin="15,30,15,10" Visibility="Collapsed">
<TextBlock Text="Select a result from the list to display additional info" Foreground="White"
FontSize="10" FontStyle="Italic" Margin="0,0,0,5" />
<ComboBox x:Name="IdentifyComboBox" SelectionChanged="IdentifyComboBox_SelectionChanged" />
<ScrollViewer MaxHeight="340" Margin="0,10,0,0">
<slData:DataGrid x:Name="IdentifyDetailsDataGrid" AutoGenerateColumns="False"
HeadersVisibility="None" LoadingRow="IdentifyDetailsDataGrid_LoadingRow">
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
<slData:DataGrid x:Name="IdentifyDetailsDataGrid2" AutoGenerateColumns="False"
HeadersVisibility="None" LoadingRow="IdentifyDetailsDataGrid_LoadingRow">
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
</ScrollViewer>
<ListBox x:Name="MyListBox" Height="200" Width="200" />
</StackPanel>
</Grid>
</StackPanel>
</Grid>
</UserControl> //Displaying Identify Results.
// Populate ComboBox with the results when Identify is complete.
private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
{
IdentifyComboBox.Items.Clear();
// Check for new results.
if (args.IdentifyResults.Count > 0)
{
// Show ComboBox and attributes DataGrid.
IdentifyResultsStackPanel.Visibility = Visibility.Visible;
// Add results to ComboBox.
foreach (IdentifyResult result in args.IdentifyResults)
{
string title = string.Format("{0} ({1})", result.Value.ToString(), result.LayerName);
IdentifyComboBox.Items.Add(title);
}
// Workaround for ComboBox bug.
IdentifyComboBox.UpdateLayout();
// Store the list of Identify results.
_lastIdentifyResult = args.IdentifyResults;
// Initialize ComboBox and fire SelectionChanged.
IdentifyComboBox.SelectedIndex = 0;
}
else
{
// Hide ComboBox and attributes DataGrid and notify the user.
IdentifyResultsStackPanel.Visibility = Visibility.Collapsed;
MessageBox.Show("No features found");
}
} var fieldsToDisplay = new List<string>() { "School Name", "Address", "Zip", "Phone", "Website", "School District" };
var attributesToDisplay = new Dictionary<string, object>();
foreach (var item in selectedFeature.Attributes)
if (fieldsToDisplay.Contains(item.Key))
attributesToDisplay[item.Key] = item.Value;
IdentifyDetailsDataGrid.ItemsSource = attributesToDisplay;
var temp = new Dictionary<string, object>();
var fields = new List<string>() {"field1", "field2"}; //fields to display
foreach(var item in feature.Attributes)
{
if(fields.Contains(item.Key))
temp[item.Key] = item.Value;
}
//more code goes here
Data = temp
public void ShowFeatures(List<IdentifyResult> results)
{
_dataItems = new List<DataItem>();
if (results != null && results.Count > 0)
{
foreach (IdentifyResult result in results)
{
Graphic feature = result.Feature;
string title = result.Value.ToString() + " (" + result.LayerName + ")";
_dataItems.Add(new DataItem()
{
Title = title,
Data = feature.Attributes
});
var fieldsToDisplay = new List<string>() { "School Name", "Address", "Zip", "Phone", "Website", "School District" };
var attributesToDisplay = new Dictionary<string, object>();
foreach (var item in feature.Attributes)
if (fieldsToDisplay.Contains(item.Key))
attributesToDisplay[item.Key] = item.Value;
if (result.LayerId == 4)
IdentifyDetailsDataGrid.ItemsSource = feature.Attributes;
IdentifyDetailsDataGrid.ItemsSource = attributesToDisplay;
if (result.LayerId == 9)
IdentifyDetailsDataGrid2.ItemsSource = feature.Attributes;
IdentifyDetailsDataGrid2.ItemsSource = attributesToDisplay;
if (result.LayerId == 14)
IdentifyDetailsDataGrid3.ItemsSource = feature.Attributes;
IdentifyDetailsDataGrid3.ItemsSource = attributesToDisplay;
}