听依赖属性的变化 [英] Listen to changes of dependency property
问题描述
有没有办法听的变化的DependencyProperty
?我希望得到通知,并执行一些操作的值改变的时候,但我不能用绑定。这是一个的DependencyProperty
另一个类的。
Is there any way to listen to changes of a DependencyProperty
? I want to be notified and perform some actions when the value changes but I cannot use binding. It is a DependencyProperty
of another class.
推荐答案
如果它是一个的DependencyProperty
单独的类的,最简单的方法是将一个值绑定到它,并听取该值的变化。
If it's a DependencyProperty
of a separate class, the easiest way is to bind a value to it, and listen to changes on that value.
如果该DP是你实现在自己的类,那么您可以注册PropertyChangedCallback 当你创建的DependencyProperty
。你可以用它来听属性的更改。
If the DP is one you're implementing in your own class, then you can register a PropertyChangedCallback when you create the DependencyProperty
. You can use this to listen to changes of the property.
如果您正在使用一个子类,你可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.windows.dependencyproperty.overridemetadata.aspx">OverrideMetadata添加自己的 PropertyChangedCallback
到DP将调用的任何原始代替。
If you're working with a subclass, you can use OverrideMetadata to add your own PropertyChangedCallback
to the DP that will get called instead of any original one.
这篇关于听依赖属性的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!