<esri:Map x:Name="Map" Background="White"
Extent="{StaticResource StartExtent}"
IsLogoVisible="False"
>
<i:Interaction.Behaviors>
<esri:ConstrainExtentBehavior ConstrainedExtent="-14055335, 5124845, -12536844, 5853025" />
</i:Interaction.Behaviors>
<!-- MAP LAYERS -->
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="Base Layer"
Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" Opacity="1.0" Visible="True" MinimumResolution="2" />
...
void QueryTaskSTR_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
FeatureSet featureSet = args.FeatureSet;
if (featureSet.Features.Count == 1)
{
try
{
Graphic selectedFeature = featureSet.Features[0];
double expandPercentage = 30;
// Zoom to selected feature (define expand percentage)
ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = selectedFeature.Geometry.Extent;
double widthExpand = selectedFeatureExtent.Width * (expandPercentage / 100);
double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100);
ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
selectedFeatureExtent.XMin - (widthExpand / 2),
selectedFeatureExtent.YMin - (heightExpand / 2),
selectedFeatureExtent.XMax + (widthExpand / 2),
selectedFeatureExtent.YMax + (heightExpand / 2));
Map.ZoomTo(displayExtent);
}
catch (Exception ex)
{
MessageBox.Show("error: Township/Range " + ex.Message);
}
else
{
MessageBox.Show("Could not find".)
}
}
}
<Button x:Name="ZoomMyFullExtent" BorderBrush="{TemplateBinding BorderBrush}" Cursor="Hand" Grid.Column="1" HorizontalAlignment="Right" Height="20" ToolTipService.ToolTip="Full Extent" VerticalAlignment="Bottom" Width="20" Click="ZoomFullExtent_Click">
<Grid Height="14" Width="14" Background="#FFE08D25">
<Ellipse Height="Auto" Stroke="White" Width="Auto"/>
<Ellipse Height="6" Stroke="White" Width="Auto"/>
<Ellipse Height="Auto" Stroke="White" Width="6"/>
</Grid>
</Button>
//routine to override the existing zoom to full extent which will zoom to world. This zooms to specified envelope.
private void ZoomFullExtent_Click(object sender, RoutedEventArgs e)
{
ESRI.ArcGIS.Client.Geometry.Envelope g = new ESRI.ArcGIS.Client.Geometry.Envelope(-8959408, 3149172, -8931633, 3170921);
MyMap.ZoomTo(g);
}