PropertyMetadata 建構函式

定義

多載

PropertyMetadata(Object)

使用屬性預設值,初始化 PropertyMetadata 類別的新實例。

PropertyMetadata(Object, PropertyChangedCallback)

使用屬性預設值和回呼參考,初始化 PropertyMetadata 類別的新實例。

PropertyMetadata(Object)

使用屬性預設值,初始化 PropertyMetadata 類別的新實例。

public:
 PropertyMetadata(Platform::Object ^ defaultValue);
 PropertyMetadata(IInspectable const& defaultValue);
public PropertyMetadata(object defaultValue);
function PropertyMetadata(defaultValue)
Public Sub New (defaultValue As Object)

參數

defaultValue
Object

Platform::Object

IInspectable

套用這個 PropertyMetadata 之屬性的預設值。

適用於

PropertyMetadata(Object, PropertyChangedCallback)

使用屬性預設值和回呼參考,初始化 PropertyMetadata 類別的新實例。

public:
 PropertyMetadata(Platform::Object ^ defaultValue, PropertyChangedCallback ^ propertyChangedCallback);
 PropertyMetadata(IInspectable const& defaultValue, PropertyChangedCallback const& propertyChangedCallback);
public PropertyMetadata(object defaultValue, PropertyChangedCallback propertyChangedCallback);
function PropertyMetadata(defaultValue, propertyChangedCallback)
Public Sub New (defaultValue As Object, propertyChangedCallback As PropertyChangedCallback)

參數

defaultValue
Object

Platform::Object

IInspectable

套用這個 PropertyMetadata 之屬性的預設值。

propertyChangedCallback
PropertyChangedCallback

要呼叫屬性變更行為的回呼參考。

範例

此範例顯示此建構函式的使用方式。 OnLabelChanged 是指 PropertyChangedCallback (未顯示) 的委派實作。 若要查看更多將這個範例放在內容中的程式碼,請參閱 自訂相依性屬性

public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
  "Label",
  typeof(String),
  typeof(ImageWithLabelControl),
  new PropertyMetadata(null,new PropertyChangedCallback(OnLabelChanged))
);
Public Shared ReadOnly LabelProperty As DependencyProperty = _
    DependencyProperty.Register("Label", _
      GetType(String), GetType(ImageWithLabelControl), _
      New PropertyMetadata(Nothing, new PropertyChangedCallback(AddressOf OnLabelChanged)))
DependencyProperty^ ImageWithLabelControl::_LabelProperty = 
    DependencyProperty::Register("Label", 
    Platform::String::typeid,
    ImageWithLabelControl::typeid, 
    ref new PropertyMetadata(nullptr,
      ref new PropertyChangedCallback(&ImageWithLabelControl::OnLabelChanged))
    );

備註

如果您想要建立具有屬性變更回呼方法但不是預設值的PropertyMetadata實例,請針對defaultValue傳遞null

如果您傳遞defaultValue的值,請確定該值的型別對透過Register呼叫的相依性屬性定義中的propertyType類型有效。 如果您已建立註冊參數與中繼資料之間的類型不符,則問題只會間接顯示本身。 當您嘗試具現化具有此相依性屬性值的類型時,將會收到執行階段錯誤,您將不會收到任何設計階段或編譯時間警告或錯誤。

另請參閱

適用於