确定是否继承了WPF DependencyProperty值 [英] Determine if a WPF DependencyProperty value is inherited
问题描述
有人知道如何确定WPF属性的值是否被继承吗?特别是,我试图确定 FrameworkElement
的 DataContext
是从父级继承还是直接在元素本身上设置.
Does anyone know how to determine if the value of a WPF property is inherited? In particular, I'm trying to determine if the DataContext
of a FrameworkElement
was inherited from the parent or set directly on the element itself.
推荐答案
DependencyPropertyHelper.GetValueSource
将为您提供 ValueSource
,其中包括用于检索 BaseValueSource
. BaseValueSource
枚举告诉您 DependencyProperty
从何处获取其值,例如从父项继承,通过样式设置或在本地设置.
DependencyPropertyHelper.GetValueSource
will give you a ValueSource
, which includes a property for retrieving the BaseValueSource
. The BaseValueSource
enumeration tells you where the DependencyProperty
is getting its value from, such as inherited from parent, set via a style or set locally.
这篇关于确定是否继承了WPF DependencyProperty值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!