This is a migrated thread and some comments may be shown as answers.

binding in rating?

4 Answers 135 Views
Rating
This is a migrated thread and some comments may be shown as answers.
sivakanth
Top achievements
Rank 1
sivakanth asked on 01 Mar 2011, 03:17 PM
Hello Telerik Team,

I have small doubt in wpf rating,
     How to bind rad rating? Bcoz i want to store the rated value in database.
our telerik version is 2010_2_0723_DEV.

4 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 03 Mar 2011, 06:26 PM
Hello sivakanth,

Binding the value of RadRating could be achieved by using a ViewModel like so:
<telerik:RadRating Width="120" Height="40" Value="{Binding RatingValue}" x:Name="ratingControl"/>
class RatingViewModel
    {
        public double RatingValue
        {
            get;
            set;
        }
    }
public MainWindow()
      {
          InitializeComponent();
          this.ratingControl.DataContext = new RatingViewModel() { RatingValue = 4.5 };
      }
Please let us know if this fits in your scenario.

Greetings,
Petar Mladenov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Dan
Top achievements
Rank 1
answered on 03 Apr 2012, 05:02 PM
This example is not working. the value is read from the binding, however the value is not set back to the binding. 

This is my workaround

    Private Sub RadRating1_ValueChanged(sender As Object, e As System.Windows.RoutedPropertyChangedEventArgs(Of Double?)) Handles RadRating1.ValueChanged
        CType(DataContext, MyObject).Rating = RadRating1.Value
    End Sub


Version: 2012.1.215.40
0
Tina Stancheva
Telerik team
answered on 04 Apr 2012, 04:33 PM
Hello Dan,

You don't have to handle the ValueChanged event. Instead you can set the binding mode of the Value property to TwoWay:
<telerik:RadRating Value="{Binding Rating, Mode=TwoWay}" />

I attached a sample project demonstrating this approach. Please give it a try and let us know if it helps.

Kind regards,
Tina Stancheva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Dan
Top achievements
Rank 1
answered on 04 Apr 2012, 04:45 PM
Thank you Tina for your response.  Your suggestion works, however, Telerik should change this to the default behavior. It's more reasonable to assume 2 way binding on every control until otherwise set that way.

Thanks again for your help.
Tags
Rating
Asked by
sivakanth
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Dan
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or