我正在使用DepdendencyObject
和PropertyChangedCallback
s,我想检测此回调中的子属性更改。问题在于DependencyPropertyChangedEventArgs
- 对象只让我看到包含DP
的属性,其中包含已更改的属性。有没有办法达到这个Subproperty?
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
)。
答案 0 :(得分:1)
从ComplexObject
(并实施Freezable
)获取Freezable
应该是否足够?
根据MSDN文档:
从Freezable派生的类获得以下功能: