Draggable WPF Controls

March 19th, 2012 by admin Leave a reply »

I have a project where I needed to have WPF controls placed on a canvas and those controls have the ability to be dragged or positioned around on the screen somewhere.  I was using some custom logic I had written to draw rectangles and textboxes to the canvas and just watching the mouse events but that was a hack because sometimes the text would get too big to fit in the textboxes.  I came across this blog post and Josh Smith has a nice little DragCanvas class that wraps up all this functionality very nicely, all you have to do is put the controls in the Xaml and you are set, very nice job Josh!

http://www.codeproject.com/Articles/15354/Dragging-Elements-in-a-Canvas

This is nice for me because I wanted to display data in a grid and have headers and be able to drag those grids around the screen.  It also allows you to do other things like set transparencies on those controls and hide and show them as well.

Advertisement

Leave a Reply