
It might look like an easy thing to but it’s not: how to draw a ruler in WPF? Problems you eventually encounter: the dots-per-inch (DPI) and device-independent-pixel (DIP) conversions, the inches and centimeters, but also the rendering and precise location of litle chips and more.
One of the things you also see often in drawing packages is the little chip representing the location of the mouse or the element under consideration. In addition, this features usually comes with guides and snap to a grid or to the guide. Now, this research was done in the context of G2 and diagramming (no surprise here I guess) but the rulers were easily developed and are useful outside this context, so I release the code here in the conviction that someone will find it useful somewhere/somehow. Note that guides, grids and snapping to guides or grids is related to rulers but cannot be part of it, so if you wish this you’ll have to implement it inside the canvas that the rulers embrace.
Don’t forget to say thank you
You can also find a color picker control here, in case you’re looking for some more WPF goodies.
Awesome
By The Bulgarian June 24, 2009 - 8:03 amDankuwel !
By Sven June 24, 2009 - 6:41 pmGraag gedaan
By Francois Vanderseypen June 24, 2009 - 8:13 pmFijn es een landgenoot hier te zien…
Thank you! Very nice!
By Andy June 24, 2009 - 8:56 pmNot sure how I will use it yet, but thank-you. I can see it as something I will face.
By Paul June 25, 2009 - 12:18 amGraaaazieeeeee
:-*
By Vittorio June 29, 2009 - 3:29 pmThank you! Very nice!
By Boy July 8, 2009 - 8:53 amThanks, this was EXACTLY what I was looking for!
By Master Po July 21, 2009 - 7:44 pmVery Cool! Thanks Very Much. Really Appreciate It.
By Chambo August 5, 2009 - 3:44 pmThank you,
By Wpf Help August 31, 2009 - 8:27 amits very nice, i have one doubt, if i set the canvas layouttransform to scaletransform for zooming the canvas? then how can make the ruler calculation
Thanks… its awesome
By saeed October 7, 2009 - 6:54 amGreat work!!
By subho100 October 12, 2009 - 7:18 amawesome. Thanks!!
By amit August 20, 2010 - 11:09 amThanks!
By OLY October 12, 2010 - 11:06 pmVery nice, This is exactly what i was looking for. i adjusted your version using guidelines to make sure every line is drawn on device pixels
By Kingsley May 10, 2011 - 2:47 pmThanks a lot
By Gabriel June 24, 2011 - 6:56 pmThis is very nice indeed. You have done a great job. This comes at a time when I need a ruler and wasn’t really looking forward to all the work that came with it. I’m happy
Thanks!
By Alessandro August 24, 2011 - 9:10 amTHANK YOUUUUUUUUUU
By Cesare October 5, 2011 - 12:22 amHi,
By Pallavi December 26, 2011 - 11:52 amthis is really useful. I could not find the way to increase soze of digits on Ruler. Any gideline for the same?
Simply Great!!!!!! No words.
By prakash December 28, 2011 - 2:39 pm