FrameworkPropertyMetadata.Inherits FrameworkPropertyMetadata.Inherits FrameworkPropertyMetadata.Inherits FrameworkPropertyMetadata.Inherits Property

定义

获取或设置一个值,该值指示依赖属性的值是否可继承。Gets or sets a value that indicates whether the value of the dependency property is inheritable.

public:
 property bool Inherits { bool get(); void set(bool value); };
public bool Inherits { get; set; }
member this.Inherits : bool with get, set
Public Property Inherits As Boolean

属性值

如果属性值可继承,则为true 否则为 falsetrue if the property value is inheritable; otherwise, false. 默认值为 falseThe default is false.

异常

已对依赖属性操作应用了元数据,因此元数据已密封,且无法设置其属性。The metadata has already been applied to a dependency property operation, so that metadata is sealed and properties of the metadata cannot be set.

示例

下面的示例从各种依赖属性字段获取默认元数据, 查询其上各种FrameworkPropertyMetadata属性的值, 并使用该信息来填充表以实现 "元数据浏览器"。The following example obtains the default metadata from various dependency property fields, queries the value of various FrameworkPropertyMetadata properties on it, and uses the information to populate a table to implement a "metadata browser".

pm = dp.GetMetadata(dp.OwnerType);
pm = dp.GetMetadata(dp.OwnerType)
FrameworkPropertyMetadata fpm = pm as FrameworkPropertyMetadata;
if (fpm!=null) {
    AffectsArrange.Text = (fpm.AffectsArrange) ? "Yes" : "No";
    AffectsMeasure.Text = (fpm.AffectsMeasure) ? "Yes" : "No";
    AffectsRender.Text = (fpm.AffectsRender) ? "Yes" : "No";
    Inherits.Text = (fpm.Inherits) ? "Yes" : "No";
    IsDataBindingAllowed.Text = (fpm.IsDataBindingAllowed) ? "Yes" : "No";
    BindsTwoWayByDefault.Text = (fpm.BindsTwoWayByDefault) ? "Yes" : "No";
}         
Dim fpm As FrameworkPropertyMetadata = TryCast(pm, FrameworkPropertyMetadata)
If fpm IsNot Nothing Then
    AffectsArrange.Text = If((fpm.AffectsArrange), "Yes", "No")
    AffectsMeasure.Text = If((fpm.AffectsMeasure), "Yes", "No")
    AffectsRender.Text = If((fpm.AffectsRender), "Yes", "No")
        [Inherits].Text = If((fpm.Inherits), "Yes", "No")
    IsDataBindingAllowed.Text = If((fpm.IsDataBindingAllowed), "Yes", "No")
    BindsTwoWayByDefault.Text = If((fpm.BindsTwoWayByDefault), "Yes", "No")

注解

属性值继承是 WPF 框架级别的WPFWPF属性系统的一项功能, 因此, 某些依赖属性可以在XAMLXAML元素树的根或附近的元素上本地设置, 然后将其值继承给子元素的逻辑树内还具有该属性的所有元素。Property value inheritance is a feature of the WPFWPF property system at the WPF framework level, whereby certain dependency properties can be locally set on an element at or near the root of a XAMLXAML element tree and then have their value inherited by all elements within the logical tree of child elements that also possess that property. 默认情况下不启用属性值继承, 并且启用它确实会影响性能。Property value inheritance is not enabled by default, and enabling it does have some performance implications. 有关详细信息,请参阅属性值继承For details, see Property Value Inheritance.

备注

尽管属性值继承可能看不到非附加依赖项属性, 但通过运行时树中的某些对象-对象分段不确定非附加属性的继承行为。Although property value inheritance might appear to work for nonattached dependency properties, the inheritance behavior for a nonattached property through certain object-object divisions in the runtime tree is undefined. 始终使用RegisterAttached来注册在元数据中Inherits指定的属性。Always use RegisterAttached to register properties where you specify Inherits in the metadata.

派生类上的PropertyMetadata属性通常在对象模型中定义为可读写。Properties on derived classes of PropertyMetadata are typically defined in the object model as read-write. 这样就可以在实例初始化后进行调整。This is so they can be adjusted after initialization of the instance. 但是, 在对RegisterAddOwnerOverrideMetadata的调用中使用元数据后, 属性系统将密封传递元数据的详细信息的元数据实例和属性现在被视为不可变。However, after the metadata is consumed as part of a call to Register, AddOwner, or OverrideMetadata, the property system will seal that metadata instance and properties that convey the specifics of the metadata are now considered immutable. 在此元数据实例上IsSealed尝试设置此属性后, 将引发异常。 trueAttempting to set this property after IsSealed is true on this metadata instance will raise an exception.

XAML 文本用法XAML Text Usage

此类的成员通常不在中XAMLXAML使用。Members of this class are not typically used in XAMLXAML.

适用于

另请参阅