The code below is what I use to draw a rectangle and Zoom up to fit the rectangle. The C# code is the same as the WPF code. The only difference is the control name. The first time you you draw the rectangle everything works as expected. The next time you do this the rectangle starts in an odd position. The C# handles this correctly. The WPF doesnt.
void winformsMap1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count > 0)
{
Mouse.OverrideCursor = Cursors.Wait;
foreach (Feature feature in winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures)
{
winformsMap1.CurrentExtent = feature.GetBoundingBox();
}
int lastIndex = winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count - 1;
if (lastIndex >= 0)
{
winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.RemoveAt(lastIndex);
}
winformsMap1.TrackOverlay.TrackMode = TrackMode.None;
// Find the closest scale for
winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();
int index = FindClosestZoom(winformsMap1.CurrentScale);
// this sets the CurrentZoomLevel;
Zoom.ZoomSlide.Value = (double)index;
Zoom.ZoomSlide.Refresh();
Mouse.OverrideCursor = Cursors.Arrow;
}
}
void winformsMap1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Control)
{
winformsMap1.TrackOverlay.TrackMode = TrackMode.Rectangle;
}
}