How to limit cursor movement in WPF based app?

后端 未结 2 1643
春和景丽
春和景丽 2021-01-21 07:33

I\'m working with a WPF app, more specifically a Canvas with draggable elements.

Once an item is being dragged, I\'d like to limit the scope of cursor movement to inside

相关标签:
2条回答
  • 2021-01-21 08:10

    You should be able to do it using the ClipCursor native API.

    0 讨论(0)
  • 2021-01-21 08:12

    There's no clean way to do this and the not-so-clean ways will make your mouse cursor "jitter" at the border of the clipping area.

    Moreover, I'd question if this is really a good idea. The user should really own the mouse and he or she generally gets frustrated when you try to artificially limit things that he or she owns.

    If you want to provide feedback when the mouse leaves your canvas, maybe you could leave the item being dragged stuck along the border while the mouse button is still down? This would tell the user that he or she has left the target area without trying to impose limitations on where the mouse can go.

    Good luck!

    0 讨论(0)
提交回复
热议问题