子依赖项属性已更改时,触发器依赖项属性已更改

时间:2020-01-16 11:17:44

标签: c# wpf binding dependency-properties dependencyobject

我有以下课程:

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");
    }

现在,如果将此类用作另一个对象的相同属性,则在更改First属性时, 此对象的OnChanged不会被触发,因此绑定也不起作用。 什么定义了父 dependencyobject 已更改?

0 个答案:

没有答案