0

I have the following class:

public class dm_fourvalues : DependencyObject
{
    [JsonProperty]
    public double First
    {
        get { return (double)GetValue(FirstProperty); }
        set
        {
            SetValue(FirstProperty, value);
        }
    }
    public static readonly DependencyProperty FirstProperty =
        DependencyProperty.Register("First", typeof(double), typeof(dm_fourvalues),
            new FrameworkPropertyMetadata(1d,
                 FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
                 new PropertyChangedCallback(OnFirstPropertyChanged)));


    private static void OnFirstPropertyChanged(DependencyObject sender,
                                               DependencyPropertyChangedEventArgs e)
    {
        dm_fourvalues uci = sender as dm_fourvalues;

        if (uci != null)
        {
            uci.OnFirstChanged();
        }
    }
    private void OnFirstChanged()
    {
        Console.WriteLine("first on dm fourvalues changed");
    }

Now if use this class as identical property on another object, when the First property gets changed, this object's OnChanged is not triggered, thus also a binding would not work. What defines that a parent dependencyobject has been changed?

yacc
  • 2,915
  • 4
  • 19
  • 33
l2rek
  • 32
  • 1
  • 5
  • Does that mean you have another DependencyObject-derived class with a dependency property of type `dm_fourvalues`? Why should that change when the First property changes? A Binding like `{Binding SomeObject.First}` would still update its target property. What exactly isn't working? Besides that, it seems odd to use DependencyObjects for binding source properties. Why don't you implement the usual INotifyPropertyChanged? – Clemens Jan 16 '20 at 11:21
  • Ok I was thinking creating similar functionality like, If I have a DProp Brush and change a value, the OnChange is triggered. Also if I would replace the Brush with another instance of Brush, it triggers the OnChange. Next thing is I need to mind the performance, so according to sources DOs are the way to go over INPChanged. In my example I would like to have a Theme DO. Its children are bound to the GUI, but should also notify when they are changed (or their members) to be added to a changes history. I was looking for some simple solution. Thank you! looking forward – l2rek Jan 28 '20 at 13:16

0 Answers0