Trigger Dependency Property Changed when child Dependency Property has been changed

341 Views Asked by At

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?

0

There are 0 best solutions below