Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6187825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:07:29+00:00 2026-05-24T02:07:29+00:00

I have a rather simple user control (RatingControl) that has a dependency property defined

  • 0

I have a rather simple user control (RatingControl) that has a dependency property defined as follows:

    public partial class RatingControl : UserControl
{
    public RatingControl()
    {
        InitializeComponent();
    }

    public static readonly DependencyProperty RatingValueProperty = DependencyProperty.Register("RatingValue", typeof(double), typeof(RatingControl), new PropertyMetadata(0.0));

    public double RatingValue
    {
        set 
        { 
            double normalizeValue = 0.0;

            if (value > 10.0)
            {
                normalizeValue = 10.0;
            }
            else if (value > 0.0)
            {
                normalizeValue = value;
            }

            SetValue(RatingValueProperty, normalizeValue);
            RenderRatingValue();
        }
        get { return (double)GetValue(RatingValueProperty); }
    }

…

This control receives properly the RatingValue if I assign it directly:

<gtcontrols:RatingControl RatingValue="2.0" />

However, if I try to assign it with data binding, it does not work. The “set” code for RatingValue is never called, nor I see data binding errors in the debug output window.
Note below that I tried to assign the same value to a standard property (Width), and in that case the value is properly passed to it.

<StackPanel>
                <TextBox Name="Test" Text="200.0" />

                <gtcontrols:RatingControl Width="{Binding ElementName=Test, Path=Text}" RatingValue="{Binding ElementName=Test, Path=Text}" />
                <TextBlock Text="{Binding ElementName=Test, Path=Text}" />
            </StackPanel>

Not only the TextBlock receives the value correctly. also RatingControl receives is for the width, properly set at 200 pixels; however, the RatingValue is not set (method set not even called)

What am I missing?
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:07:30+00:00Added an answer on May 24, 2026 at 2:07 am

    The thing is that the binding system does not use the CLR property wrapper (getter and setter) to assign the value of a dependency property. Those are there just for convenience, so you could use the property just like a normal property in your code. Internally it uses SetValue()/GetValue() methods.

    So, the proper place for the value normalization would be the property changed callback for the dependency property:

    public static readonly DependencyProperty RatingValueProperty =
        DependencyProperty.Register("RatingValue", typeof(double), typeof(RatingControl), 
        new PropertyMetadata(0.0, new PropertyChangedCallback(RatingValuePropertyChanged))));
    
    static void RatingValuePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        var ratingControl = (RatingControl)sender;
        var val = (double)e.NewValue;
    
        double normalizeValue = 0.0;
    
        if (val > 10.0)
        {
            normalizeValue = 10.0;
        }
        else if (val > 0.0)
        {
            normalizeValue = val;
        }      
    
        ratingControl.RatingValue = normalizeValue;  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a rather simple site (minimal JS) with plain html and CSS. It
Heavy emphasis on simple. I've never made an installer and I'd rather not have
I have rather large input XML files that must be converted to a given
I have a rather big number of source files that I need parse and
I have a rather large (many gigabytes) table of data in SQL Server that
Trying to implement what I thought was a simple concept. I have a user
Which version control system would you recommend for: single user looking for simple, easy
I have an ASP.NET MVC application that allows the user to upload a file
I want to implement a rather complex CurveEditor that has to support the usual
Ok, what I'm doing is (I think) rather simple. I have a LINQ-to-SQL data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.