Star Selector Control Updated

In my spare time, I have been re-writing the Star Selector control that is part of Silverlight Contrib.  I re-wrote this control because there were several things I wanted to accomplish.  This re-write includes quite a few new features.  I will highlight them in the next few sections:

Half-Star Selection

The control supports enabling half-star selection.  To enable or disable this feature, simply set the AllowHalfStarSelection property accordingly.  The default value is false.

 star_selector

DisplayValue and Value Property Data Types

The DisplayValue and Value properties have been changed from an Integer to a double data type.  This allows you to select half-stars and the control will reflect the specified value by rounding up or down to the nearest half-star when AllowHalfStarSelection is true.

DisplayValue reflects which stars will be visible.  Value reflects what the user has chosen.  I have split this concept into 2 properties to allow for more flexibility  when using the control.

For example, suppose you wanted to start off with an empty rating.  Once the user selects a value, you want to pull down the newly calculated average for all ratings.  The following code would allow you to achieve this:

void Page_Loaded(object sender, RoutedEventArgs e) 
{
StarSelector1.DisplayValue = 0;
}

private void StarSelector1_ValueChanged(object sender, RoutedEventArgs e)
{
// Calculate Average including (StarSelector1.Value)
StarSelector1.DisplayValue = GetCalculatedAverage();
}

Half-Star Templatability

half_heart_selection

Maximum Property

The Maximum property allows you to specify the number of stars that will be displayed on the control.  The default value is 5.

ReadOnly Property

Sometimes you just need to show a rating without allowing the user to interact with the control.  The ReadOnly property allows for this.  The default value is false.

Disabled Property

The new star selector control also has a Disabled property.  You can also provide a Disabled state in the control template if you wish.  The default value is false.

disabled_star

disabled_heart

You can try out a live demo of the control and download the source code below:

Live Demo

Enjoy!


Feedback

# Star Selector Control Updated - Page Brooks

Gravatar Thank you for submitting this cool story - Trackback from DotNetShoutout 5/2/2009 2:21 PM | DotNetShoutout

# re: Star Selector Control Updated

Gravatar Looks great - one little thing I noticed is that if you toggle the AllowHalfStar option while half a star is displayed it doesn't go away. Not sure if you care or not... 5/4/2009 9:39 AM | Jack

# re: Star Selector Control Updated

Gravatar Great work.
How about re-write it in WPF?! 5/6/2009 3:20 AM | Ruddy

# re: Star Selector Control Updated

Gravatar Jack,
Thanks for the feedback! I had not noticed it before, but I will correct this behavior. 5/8/2009 8:36 AM | pbrooks

# re: Star Selector Control Updated

Gravatar Ruddy,

I'll consider it! 5/8/2009 8:38 AM | pbrooks

Comments have been closed on this topic.