.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> WPF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Rating Control in WPF Toolkit

Posted By:Diptimaya Patra       Posted Date: May 10, 2010    Points: 25    Category: WPF    URL: http://www.dotnetspark.com  

Rating Control in WPF Toolkit. In this article we will see how we can use the Rating Control in WPF Application.


Rating Control is introduced in 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.


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


Or, we can add it in Expression Blend.


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


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

The following figure shows the 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 ListBox.
public class Movies
    public string Name { get; set; }
    public double Rated { get; set; }

Above Class represents our Movie Structure.

public Window1()
    ObservableCollection movieList = new ObservableCollection 
        new Movies{ Name="Avtaar",Rated=0},
        new Movies{ Name="Smoking Aces 2",Rated=0},
        new Movies{ Name="2012",Rated=0},
        new Movies{ Name="The Spy Next Door",Rated=0},
        new Movies{ Name="3 Idiots",Rated=0},
        new Movies{ Name="Teen Patti",Rated=0},
        new Movies{ Name="My Name Is Khan",Rated=0},
        new Movies{ Name="Shrek 4",Rated=0},
        new Movies{ Name="Astro Boy",Rated=0},
        new Movies{ Name="Some 1",Rated=0},
        new Movies{ Name="Some 2",Rated=0},
        new Movies{ Name="Some 3",Rated=0},
        new Movies{ Name="Some 4",Rated=0},
    lbMovies.ItemsSource = movieList;

    ratingFav.ValueChanged += new

As you see in above code display, we have used ObservableCollection, because in run time we would be seeing what value we have stored for each Movie.


Above code display shows the DataTemplate for our Data to be bound.

Now run the application we would test the ListBox with Sample data.


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


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.


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

You can also download the sample project used in the above example.

Hope this article helps.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend