
Someone asked me recently how to create a WPF application where the user can drag a blue rectangle around the screen. I solved that puzzle, but kept generalizing the solution until it became possible to drag any UIElement on a Canvas (including Buttons, Images, ComboBoxs, Grids, etc.) This article explores a class called CanvasDragManager, which can be attached to any Canvas, enabling the user to drag the objects inside the Canvas. The CanvasDragManager class also provides support for modifiying the z-order of elements in a Canvas (such as ‘bring to front’ and ‘send to back’ operations).
|