I have a Canvas in which user can add UserControl subclasses containing a form. User should be able to drag these UserControl around the Canvas.
What\'s the best pr
If someone wants to quickly see this effect, here is a minimal solution using only MouseMove
event.
The Layout
Code behind
private void OnMouseMove(object sender, MouseEventArgs e)
{
if (e.Source is Shape shape)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point p = e.GetPosition(canvas);
Canvas.SetLeft(shape, p.X - shape.ActualWidth / 2);
Canvas.SetTop(shape, p.Y - shape.ActualHeight / 2);
shape.CaptureMouse();
}
else
{
shape.ReleaseMouseCapture();
}
}
}