I’ve been using WPF a bit more lately and had the need for a ratings control. After searching for a bit, I came across this one on Nicke Andersson's blog, which worked perfectly for the project I was working on.
After, though, I was curious, so I decided to make some modifications to the control to improve it and to help me learn a bit more about WPF user controls.
My idea was to extend the rating control to handle 1/2 stars, so instead of only allowing you to select a value from 0-5, you could also rate something as 4.5/5 for example. I also like the look of some rating controls on the web, which highlight the stars as you hover over them.
I started with Nicke's sample project and began by tearing apart the star shape path and splitting it into two – a left half and a right half. I managed to get the XAML code working well enough to display 5 stars, each built from the 2 halves. After this, I hacked the backing code a little bit to handle the new rating values and wired up some events for the hover effect.
This is what the finished control looks like :
You can download the source here.