我将DepdendencyObject
s 与PropertyChangedCallback
s 一起使用,并且我想检测此回调中的子属性更改。问题是DependencyPropertyChangedEventArgs
-Object 只让我看到包含DP
更改的属性的属性。有没有办法达到这个子属性?
class MainClass : DepencencyObject
{
public ComplexObject MainProperty
{
get { return (ComplexObject)GetValue(MainPropertyProperty); }
set { SetValue(MainPropertyProperty, value); }
}
public static readonly DependencyProperty MainPropertyProperty =
DependencyProperty.Register("MainProperty",
typeof(ComplexObject), typeof(MainClass),
new PropertyMetadata(new ComplexObject([...])));
private static void MainProperty_PropertyChangedCallback(... DependencyPropertyChangedEventArgs e)
{
// Unable to detect a change, if 'ComplexObject.SubProperty'
// changes; it is shown like a change of 'MainProperty'
}
}
class ComplexObject : DepencencyObject
{
public int SubProperty
{
get { return (int)GetValue(SubPropertyProperty); }
set { SetValue(SubPropertyProperty, value); }
}
public static readonly DependencyProperty SubPropertyProperty =
DependencyProperty.Register("SubProperty",
typeof(int), typeof(ComplexObject),
new PropertyMetadata(0));
}
有人会
(new MainClass()).MainProperty.SubProperty = 100000;
并且 PropertyChangedCallback 被调用,因为MainProperty
改变(不是SubProperty
)。