Thanks bb1769, your codes are very useful for me.my codeprivate void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
// Clear previous results
GraphicsLayer graphicsLayer = mainMap.Layers["QueryGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
// Check for new results
FeatureSet featureSet = args.FeatureSet;
if (featureSet.Features.Count > 0)
{
// Add results to map
foreach (Graphic resultFeature in featureSet.Features)
{
resultFeature.Symbol = QueryResultsMarkerSymbol;
graphicsLayer.Graphics.Add(resultFeature);
//zoom to some level if your layer is TiledMapServiceLayer
TiledMapServiceLayer tiledLayer = mainMap.Layers["mainMapLayer"] as TiledMapServiceLayer;
Lod lod = tiledLayer.TileInfo.Lods[5]; //zoom to 5 level
double halfWidth = lod.Resolution * mainMap.ActualWidth / 2;
double halfHeight = lod.Resolution * mainMap.ActualHeight / 2;
ESRI.ArcGIS.Client.Geometry.MapPoint newMapPoint = (MapPoint)resultFeature.Geometry;
Envelope newExtent = new Envelope(newMapPoint.X - halfWidth, newMapPoint.Y - halfHeight, newMapPoint.X + halfWidth, newMapPoint.Y + halfHeight);
mainMap.ZoomTo(newExtent); //thanks for bb1769
}
}
else
{
MessageBox.Show("No features found");
}
}