Hello,
I have a Canvas inside a ScrollViewer; the Canvas will have several objects drawn on it.
I would like to be able to Pan -- scroll -- the Canvas using the mouse: LButtonDown - move mouse - LButtonUp.
In the .xaml, I have a TranslateTransform for the Canvas.
Code:
private void MapCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
ClickPosition = e.GetPosition(MapCanvas);
Debug.WriteLine("LButtonDown: " + ClickPosition.ToString());
MapCanvas.CaptureMouse();
IsMouseCaptured = true;
e.Handled = true;
}
private void MapCanvas_MouseMove(object sender, MouseEventArgs e)
{
if (IsMouseCaptured)
{
Point point = new Point(e.GetPosition(MapCanvas));
Debug.WriteLine("\t" + point.ToString());
MapPanTransform.X = point.X - ClickPosition.X;
MapPanTransform.Y = point.Y - ClickPosition.Y;
}
}
This results in some strange points appearing in MapCanvas_MouseMove:
LButtonDown 557,469
556,469
368,472
555,469
367,472
554,469
365,472
553,469
Any ideas on what's going on? Thanks.