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.
![]() |
WPF Ruler 1.5 (Tue 27 Apr 2010) |
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.
Update:
- Thanks to Raf Lenfers for contributing to the scaling
- Updated the code to VS2010 (Arpil 2010).






