binding in rating?

5 posts, 0 answers
  1. sivakanth
    sivakanth avatar
    50 posts
    Member since:
    Dec 2010

    Posted 01 Mar 2011 Link to this post

    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.

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 03 Mar 2011 Link to this post

    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!
  3. UI for WPF is Visual Studio 2017 Ready
  4. Dan
    Dan avatar
    5 posts
    Member since:
    Sep 2008

    Posted 03 Apr 2012 Link to this post

    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
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 04 Apr 2012 Link to this post

    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 >>
  6. Dan
    Dan avatar
    5 posts
    Member since:
    Sep 2008

    Posted 04 Apr 2012 Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready