PropertyMetadata.DefaultValue 屬性

定義

取得或設定相依性屬性的預設值。Gets or sets the default value of the dependency property.

public:
 property System::Object ^ DefaultValue { System::Object ^ get(); void set(System::Object ^ value); };
public object DefaultValue { get; set; }
member this.DefaultValue : obj with get, set
Public Property DefaultValue As Object

屬性值

屬性的預設值。The default value of the property. 以無參數的函PropertyMetadata式建立之實例上的預設值UnsetValue將會是。The default value on a PropertyMetadata instance created with the parameterless constructor will be UnsetValue.

例外狀況

一旦建立,便無法設定為值 UnsetValueCannot be set to the value UnsetValue once created.

一旦套用至相依性屬性作業,便無法設定中繼資料屬性。Cannot set a metadata property once it is applied to a dependency property operation.

備註

DefaultValue在物件模型中定義為讀寫。DefaultValue is defined in the object model as read-write. DefaultValue 如此PropertyMetadata一來, 就可以在初始化物件本身之後調整。This is so DefaultValue can be adjusted after initialization of the PropertyMetadata object itself. 不過, 一旦使用中繼資料做為RegisterAddOwnerOverrideMetadata呼叫的一部分, 屬性系統就會密封該中繼資料實例, 而屬性現在會被視為不變。However, once the metadata is consumed as part of a call to Register, AddOwner, or OverrideMetadata, the property system will seal that metadata instance and the properties are now considered immutable. 嘗試設定DefaultValue一次IsSealedtrue在此中繼資料實例上, 將會引發例外狀況。Attempting to set DefaultValue once IsSealed is true on this metadata instance will raise an exception.

雖然這是每個無參數的函式的defaultValue預設UnsetValue值, 但不能DefaultValue使用或方法來設定的。Although it is the default per the parameterless constructor, a defaultValue of UnsetValue cannot be set using either DefaultValue or the constructor. 嘗試這麼做會引發例外狀況。Attempting to do so will raise an exception.

XAML 文字使用方式XAML Text Usage

此類型的成員通常不會在中XAMLXAML使用。Members of this type are not typically used in XAMLXAML.

適用於