I'm thinking at the better way to manage a "workspace" in my application, where the user could move things in this space, and could pan for instance.
Let's imagine I have my application interface, with some buttons all around, a treeview etc. and in the middle, a Canvas with some widgets the user can move and work with, and he could pan this space to move in it.
For the pan, I was thinking to handle the MouseLeftButtonDown in this space (that switch a boolean "UserMoving" to true), and on the MouseMove, to apply on translation to the space (from the Delta between the 2 events), until I detect a MouseLeftButtonUp, to know he has stopped (UserMoving to false). The problem is that if the user "mouse left button up" not on the space itself (a Canvas), I will never know he has released the mouse. What's the best to manage the fact that he can release the pan (or the drag&drop of a widget) wherever in the application?
Do anybody has already manage something like that and can help me?
You should call the UIElement.CaptureMouse on your Canvas at the mouse down. This will keep the canvas receiving mouse events, even if the user moves outside of it's region.
On mouse up, call ReleaseMouseCapture.