In Focus

Rating Control In WPF Toolkit

Rating Control was introduced in WPF Toolkit February 2010 release. In this article we will see how we can use the Rating Control.

Rating Control was introduced in the WPF Toolkit February 2010 release. In this article, we will see how we can use the Rating Control.

Crating WPF Application Project

Fire up Visual Studio 2008 and create a WPF application and name the project as RatingInWPF.

Crating WPF Application Project

We can add the rating control by adding the following DLL from the WPF Toolkit directory.

Crating WPF Application Project

Or, we can add it in Expression Blend.

Crating WPF Application Project

After adding the Rating control, add a few RatingItem Controls. Suppose we need to rate out of 5, then add 5 RatingItems.

Rating control

By default,  content comes with Rating Item control, so remove the content value.

The following figure shows the hierarchy in object and timeline pane.

hierarchy in object and timeline pane

Now, we will use the Rating Control to rate Movies displayed in a list and store it.

So, let's create some sample Data and Bind it to the ListBox.

Rating Control in WPF Toolkit

The above class represents our Movie structure.

Rating Control in WPF Toolkit

As you can see in the above code display, we have used ObservableCollection, because at runtime, we would be seeing what value we have stored for each Movie.

Rating Control in WPF Toolkit

The above code display shows the DataTemplate for our data to be bound.

Now, run the application and we will test the ListBox with sample data.

ListBox with Sample data

Now, we will have two events - one from RatingControl and another from ListBox; as follows, and add the below code in the respective event handlers.

Rating Control in WPF Toolkit

The highlighted code has to be entered in the Constructor. For some reason, the event cannot be created in XAML.

That's it; we are ready to test our application.

Rating Control in WPF Toolkit

As we are using ObservableCollection the change in the Collection is instantly affected. So, changing the Rating Value will change in the Collection.

I hope this article helps.