FrameworkPropertyMetadata.Inherits 屬性

定義

取得或設定值,指出相依性屬性的值是否為可繼承。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. 嘗試在這個中繼資料實例IsSealedtrue設定這個屬性之後, 就會引發例外狀況。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.

適用於

另請參閱