Hi i tryied to move line object in my app.
Xaml:
<Canvas x:Name="canvas" Height="300" Width="350" MouseDown="Canvas_MouseDown" MouseMove="Canvas_MouseMove" MouseUp="Canvas_MouseUp" Background="Transparent" />
Code Behind:
private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
{
startPoint = e.GetPosition(canvas);
if (e.OriginalSource is Line)
{
linia = (Line)e.OriginalSource;
if(!LineFocus)
LineFocus = true;
return;
}
else
LineFocus = false;
}
private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
var pos = e.GetPosition(canvas);
TranslateTransform ruch = new TranslateTransform(pos.X - startPoint.X, pos.Y - startPoint.Y);
linia.RenderTransform = ruch;
}
It works fine my line is moved, but when I try to move it again it is moving from oryginal place (the place when i draw them at the very first time). When I checked it by MessageBox() with this:
...
linia = (Line)e.OriginalSource;
MessageBox.Show(linia.X1 + linia.Y1 + linia.X2 + linia.Y2);
...
Allways return exactly the same values even after move, so what is the reason of that?