WPF Ruler

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 [...]

Chip

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.

Download WPF Ruler 1.5 (Tue 27 Apr 2010)

Don’t forget to say thank you ;)

G2 rulerYou 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).
 

13 Responses to “WPF Ruler”

  1. Sven says:

    Dankuwel !

  2. Graag gedaan :)
    Fijn es een landgenoot hier te zien…

  3. Andy says:

    Thank you! Very nice!

  4. Paul says:

    Not sure how I will use it yet, but thank-you. I can see it as something I will face.

  5. Vittorio says:

    Graaaazieeeeee :-) :-*

  6. Boy says:

    Thank you! Very nice!

  7. Master Po says:

    Thanks, this was EXACTLY what I was looking for!

  8. Chambo says:

    Very Cool! Thanks Very Much. Really Appreciate It.

  9. Wpf Help says:

    Thank you,
    its 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

  10. saeed says:

    Thanks… its awesome

  11. subho100 says:

    Great work!!

  12. amit says:

    awesome. Thanks!!

Leave a Reply