2

As mentioned in this question, there are at least two ways by which I can be notified that the value bound to a dependency property has changed:

  1. DependencyPropertyDescriptor.AddValueChanged
  2. DependencyProperty.OverrideMetadata on a derived class with my own PropertyChangedCallback.

This is all working fine but I need to be notified only when the actual binding is set on the property not every time the value changes. Is there a way to register a callback for this or an event I need to listen to?

I have looked in MSDN on the classes DependencyProperty, DependencyObject, BindingOperations and DependencyPropertyDescriptor.

Community
  • 1
  • 1
Marcel Gosselin
  • 4,610
  • 2
  • 31
  • 54

1 Answers1

0

I don't think there is an "official way" to do that, although I had the same problem some days ago and came up with a quite stupid but at least efficient workaround

private bool isSet = false;

public static readonly DependencyProperty DummyProperty =
            DependencyProperty.Register("DummySource",
                                        typeof(DummyType),
                                        typeof(WhateverYouWant),
                                        new PropertyMetadata((s, a) =>
                                        {
                                          if (!isSet)
                                          {
                                            //Blah blah about what you wanna do

                                            isSet = true
                                          }
                                        }));

Works fine for me, should do the trick for you as well :)

Damascus
  • 6,553
  • 5
  • 39
  • 53
  • I did something similar myself but I was hoping a better solution was possible. I'll leave this question open for a few days hoping somebody knows how to do this. If nobody shows up I'll accept your answer. Thanks. – Marcel Gosselin Jul 22 '11 at 05:21