Select to view content in your preferred language

Identify Tool - Silverlight Examples

1075
6
04-06-2011 07:36 AM
BrandonIves
Emerging Contributor
I am new to developing in silverlight and I am trying to go through the examples found in the resource center. I copied and pasted the code for the identify tool into VS2010 and I am getting an error on building the project:

"The type or namespace name 'IdentifyResults' could not be found (are you missing a using directive or an assembly reference?)

Did I miss a step somewhere? Am I missing a reference? I added all of the references that the example noted. Thanks for any input.

Here are the two examples I was using:

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify
http://help.arcgis.com/en/webapi/silverlight/help/index.html#/Identify_task/01660000001m000000/
0 Kudos
6 Replies
nakulmanocha
Esri Regular Contributor
I am able to run the sample without any issues. What exactly is IdentifyResults? The only place it appears in the sample is args.IdentifyResults. I know there is IdentifyResult but I don't see IdentifyResults. Could you please attach your complete code here? Thanks
0 Kudos
BrandonIves
Emerging Contributor
Here is my code. Below I added an arrow to show the error.


using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
using ESRI.ArcGIS.Client.Symbols;

namespace IdentifyExpressionBlend
{
public partial class MainPage : UserControl
{

----------------> private List<IdentifyResults> _lastIdentifyResult;
public MainPage()
{
// Required to initialize variables
InitializeComponent();
}

// Do identify when Map is clicked
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs args)
{
// Show an icon at the identify location
GraphicsLayer graphicsLayer = MyMap.Layers["IdentifyIconGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
{
Geometry = args.MapPoint,
Symbol = IdentifyLocationSymbol
};
graphicsLayer.Graphics.Add(graphic);

// Identify task initialization
IdentifyTask identifyTask = new IdentifyTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
"Demographics/ESRI_Census_USA/MapServer");
identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
identifyTask.Failed += IdentifyTask_Failed;

// Initialize Identify parameters. Specify searching of all layers.
IdentifyParameters identifyParameters = new IdentifyParameters();
identifyParameters.LayerOption = LayerOption.all;

// Pass current Map properties to identify parameters
identifyParameters.MapExtent = MyMap.Extent;
identifyParameters.Width = (int)MyMap.ActualWidth;
identifyParameters.Height = (int)MyMap.ActualHeight;

// Identify features at the click point
identifyParameters.Geometry = args.MapPoint;

identifyTask.ExecuteAsync(identifyParameters);
}

// Populate ComboBox with 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 attribuets 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 user
IdentifyResultsStackPanel.Visibility = Visibility.Collapsed;
MessageBox.Show("No features found");
}
}

// Show geometry and attributes of selected feature
void IdentifyComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Clear previously selected feature from GraphicsLayer
GraphicsLayer graphicsLayer = MyMap.Layers["ResultsGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();

// Check that ComboBox has a selected item. Needed because SelectionChanged fires
// when ComboBox.Clear is called.
if (IdentifyComboBox.SelectedIndex > -1)
{
// Update DataGrid with selected feature's attributes
Graphic selectedFeature = _lastIdentifyResult[IdentifyComboBox.SelectedIndex].Feature;
IdentifyDetailsDataGrid.ItemsSource = selectedFeature.Attributes;

// Apply symbol and add selected feature to map
selectedFeature.Symbol = SelectedFeatureSymbol;
graphicsLayer.Graphics.Add(selectedFeature);
}
}

// Notify when identify fails
private void IdentifyTask_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Identify failed: " + args.Error);
}

}
}
0 Kudos
nakulmanocha
Esri Regular Contributor
The List class is available within System.Collections.Generic namespace.

You need to add the following as one of your using statements

using System.Collections.Generic;
0 Kudos
BrandonIves
Emerging Contributor
I actually do have "using system.collections.generic;" as a using statement. Not sure why it didn't paste. I litterally copied and pasted the code and then added additional Using Statements. I took a screenshot to show the error.
0 Kudos
ChristopherHill
Deactivated User
the class is IdentifyResult not IdentifyResult(s) you added an "s" to the end. ^_^
0 Kudos
BrandonIves
Emerging Contributor
Doh. Good eyes, thank you so much. Thanks to nmanocha also!
0 Kudos