If your query results are added to a new graphics layer the default settings for layer will apply. Meaning all fields as defined by your service will be added, be visible and have alias names as defined by the service.
What you are saying here is what I excpect to happen but unfortunatley is not the case (for me anyway). I have 2 seperate tools in which one performs a spatial query and the other a attribute query. Both add a new graphics layer if the layer does not exist and then adds the features from the query results to the graphics layer. I based my code off of the ESRI samples. Here is the relevant portion of the code. Maybe I am creating the layer incorrectly.
// Retrieve or create a graphics layer to use for displaying results
GraphicsLayer graphicsLayer = null;
if (featureSet.Features[0].Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint)
graphicsLayer = GetOrCreateLayer("Policy Spatial Query Results", "CustomStrobeMarkerSymbol");
else if (featureSet.Features[0].Geometry is ESRI.ArcGIS.Client.Geometry.Polyline)
graphicsLayer = GetOrCreateLayer("Polyline Spatial Query Results", "RedLineSymbol");
else if (featureSet.Features[0].Geometry is ESRI.ArcGIS.Client.Geometry.Polygon)
graphicsLayer = GetOrCreateLayer("Polygon Spatial Query Results", "RedFillSymbol");
string RecCount = featureSet.Features.Count.ToString();
string strRecordLimit = null;
// Add results to the graphics layer
graphicsLayer.ClearGraphics(); //clear out any old features
foreach (Graphic feature in featureSet.Features)
graphicsLayer.Graphics.Add(feature);
// Add the results graphics layer to the map if it has not already been added and the results to map checkbox is checked
if (chkResults2Map.IsChecked == true)
{
if (MapApplication.Current.Map.Layers[graphicsLayer.ID] == null)
MapApplication.Current.Map.Layers.Add(graphicsLayer);
}
}
private GraphicsLayer GetOrCreateLayer(string layerId, string renderer)
{
Layer layer = MapApplication.Current.Map.Layers[layerId];
if (layer != null && layer is GraphicsLayer)
{
return layer as GraphicsLayer;
}
else
{
GraphicsLayer gLayer = new GraphicsLayer()
{
ID = layerId,
Renderer = new SimpleRenderer()
{
Symbol = Resources[renderer] as Symbol
}
};
gLayer.SetValue(MapApplication.LayerNameProperty, layerId);
return gLayer;
}
}