FrameworkPropertyMetadata.Inherits Property


取得或設定值,指出相依性屬性的值是否為可繼承。Gets or sets a value that indicates whether the value of the dependency property is inheritable.

 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

Property Value


如果屬性值是可繼承的,即為 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. 嘗試在這個中繼資料實例上 true IsSealed 之後設定這個屬性,將會引發例外狀況。Attempting 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.

Applies to

See also