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

  • SEARCH
  • Home
  • 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 6246105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:37:41+00:00 2026-05-24T12:37:41+00:00

I think I’m missing something very fundamental here. I’ve created a UserControl with a

  • 0

I think I’m missing something very fundamental here.

I’ve created a UserControl with a DependencyProperty, defined as such:

    public static DependencyProperty SpinnerColourProperty = DependencyProperty.Register("SpinnerColour", typeof(Color), typeof(LoadingControl), new PropertyMetadata(Colors.Black));

    public Color SpinnerColour
    {
        get
        {
            return (Color)GetValue(SpinnerColourProperty);
        }
        set
        {
            SetColour(value);
            SetValue(SpinnerColourProperty, value);
        }
    }

(Yes, I prefer British-English… so sue me :P)

The SetColour method, as expected, changes how the control looks.

If in my code I write customControl1.SpinnerColour = Colors.Red then the control will correctly change the colour both of the property and of the visual effect which is applied through the setter. (I can even observe this change if I play around with the property in Visual Studio’s designer!)

However, if I apply a data binding to that property and then change the element it’s bound to, the value of the property will change, but the setter will never be called and the actual display will never change.

So for example, if I define a button and my control:

  <my:MyControl x:Name="myControl1" SpinnerColour="{Binding ElementName=button1, Path=Background.Color, Mode=TwoWay}" />
  <Button Content="Button" Height="23" Name="button1" Click="button1_Click" />

And the Click event changes the colour of the buttons background as such:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        button1.Background = new SolidColorBrush(Colors.Red);
    }

Then if I check the SpinnerColour property using the debugger, it’ll be red. However, as I wrote, the setter is never called, and the actual control never changes it’s colour.

What am I doing wrong?

  • 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-24T12:37:42+00:00Added an answer on May 24, 2026 at 12:37 pm

    You’re misusing dependency properties.
    The native CLR property that calls SetValue is only used when you set the property in code.
    The binding infrastructure calls SetValue directly (instead of using reflection), so your code never runs.

    You should never put any code other than GetValue and SetValue in a DependencyProeprty wrapper

    Instead, you need to specify a ValueChangedCallback in the DependencyProperty registration, as the second parameter to the PropertyMetadata constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I'm missing something basic here. Any explanation or pointers to previously asked
I think I'm missing something basic here. Why is the third IF condition true?
I think I got all the steps down but I must be missing something
I think this may sound very straight forward, but still something is not working
I think most people here understand the importance of fully automated builds. The problem
Think of the following code: static int Main() { byte[] data = File.ReadAllBytes(anyfile); SomeMethod(data);
I think it will be very hard for you to read the code but
I think I have a very popular problem, but not found answer for it
Think I'm missing a basic concept. I want to generate html by traversing through
I think that I am misunderstanding something about how jquery $(this) works. In my

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.