DependencyProperty.Register 方法

定義

登錄相依性屬性。

多載

Register(String, Type, Type)

使用指定的屬性名稱、屬性類型和擁有者類型以註冊相依性屬性。

Register(String, Type, Type, PropertyMetadata)

請使用指定的屬性名稱、屬性類型、擁有者類型和屬性中繼資料登錄相依性屬性。

Register(String, Type, Type, PropertyMetadata, ValidateValueCallback)

使用指定的屬性名稱、屬性類型、擁有者類型、屬性中繼資料和屬性的值驗證回呼,註冊相依性屬性。

Register(String, Type, Type)

使用指定的屬性名稱、屬性類型和擁有者類型以註冊相依性屬性。

public:
 static System::Windows::DependencyProperty ^ Register(System::String ^ name, Type ^ propertyType, Type ^ ownerType);
public static System.Windows.DependencyProperty Register (string name, Type propertyType, Type ownerType);
static member Register : string * Type * Type -> System.Windows.DependencyProperty
Public Shared Function Register (name As String, propertyType As Type, ownerType As Type) As DependencyProperty

參數

name
String

要註冊之相依性屬性的名稱。 名稱在擁有者類型的註冊命名空間內必須是唯一的。

propertyType
Type

屬性的類型。

ownerType
Type

正在註冊相依性屬性的擁有者類型。

傳回

應該用來設定類別之 public static readonly 欄位值的相依性屬性的識別項。 若為以程式設計方式設定其值或取得中繼資料等的作業,之後就會用識別項參考相依性屬性。

範例

public static readonly DependencyProperty IsDirtyProperty = DependencyProperty.Register(
  "IsDirty",
  typeof(Boolean),
  typeof(AquariumObject3)
);
Public Shared ReadOnly IsDirtyProperty As DependencyProperty = DependencyProperty.Register("IsDirty", GetType(Boolean), GetType(AquariumObject3))

備註

如需相依性屬性註冊的詳細資訊,請參閱 DependencyProperty

另請參閱

適用於

Register(String, Type, Type, PropertyMetadata)

請使用指定的屬性名稱、屬性類型、擁有者類型和屬性中繼資料登錄相依性屬性。

public:
 static System::Windows::DependencyProperty ^ Register(System::String ^ name, Type ^ propertyType, Type ^ ownerType, System::Windows::PropertyMetadata ^ typeMetadata);
public static System.Windows.DependencyProperty Register (string name, Type propertyType, Type ownerType, System.Windows.PropertyMetadata typeMetadata);
static member Register : string * Type * Type * System.Windows.PropertyMetadata -> System.Windows.DependencyProperty
Public Shared Function Register (name As String, propertyType As Type, ownerType As Type, typeMetadata As PropertyMetadata) As DependencyProperty

參數

name
String

要註冊之相依性屬性的名稱。

propertyType
Type

屬性的類型。

ownerType
Type

正在註冊相依性屬性的擁有者類型。

typeMetadata
PropertyMetadata

相依性屬性的屬性中繼資料。

傳回

應該用來設定類別之 public static readonly 欄位值的相依性屬性的識別項。 若為以程式設計方式設定其值或取得中繼資料等的作業,之後就會用識別項參考相依性屬性。

備註

如需相依性屬性註冊的詳細資訊,請參閱 DependencyProperty

另請參閱

適用於

Register(String, Type, Type, PropertyMetadata, ValidateValueCallback)

使用指定的屬性名稱、屬性類型、擁有者類型、屬性中繼資料和屬性的值驗證回呼,註冊相依性屬性。

public:
 static System::Windows::DependencyProperty ^ Register(System::String ^ name, Type ^ propertyType, Type ^ ownerType, System::Windows::PropertyMetadata ^ typeMetadata, System::Windows::ValidateValueCallback ^ validateValueCallback);
public static System.Windows.DependencyProperty Register (string name, Type propertyType, Type ownerType, System.Windows.PropertyMetadata typeMetadata, System.Windows.ValidateValueCallback validateValueCallback);
static member Register : string * Type * Type * System.Windows.PropertyMetadata * System.Windows.ValidateValueCallback -> System.Windows.DependencyProperty
Public Shared Function Register (name As String, propertyType As Type, ownerType As Type, typeMetadata As PropertyMetadata, validateValueCallback As ValidateValueCallback) As DependencyProperty

參數

name
String

要註冊之相依性屬性的名稱。

propertyType
Type

屬性的類型。

ownerType
Type

正在註冊相依性屬性的擁有者類型。

typeMetadata
PropertyMetadata

相依性屬性的屬性中繼資料。

validateValueCallback
ValidateValueCallback

回呼的參考,應該執行對相依性屬性值之一般類型驗證以外的任何自訂驗證。

傳回

應該用來設定類別之 public static readonly 欄位值的相依性屬性的識別項。 若為以程式設計方式設定其值或取得中繼資料等的作業,之後就會用識別項參考相依性屬性。

範例

下列範例會註冊相依性屬性,包括未顯示回呼定義的驗證回呼 (;如需回呼定義的詳細資訊,請參閱 ValidateValueCallback) 。

public static readonly DependencyProperty CurrentReadingProperty = DependencyProperty.Register(
    "CurrentReading",
    typeof(double),
    typeof(Gauge),
    new FrameworkPropertyMetadata(
        Double.NaN,
        FrameworkPropertyMetadataOptions.AffectsMeasure,
        new PropertyChangedCallback(OnCurrentReadingChanged),
        new CoerceValueCallback(CoerceCurrentReading)
    ),
    new ValidateValueCallback(IsValidReading)
);
public double CurrentReading
{
  get { return (double)GetValue(CurrentReadingProperty); }
  set { SetValue(CurrentReadingProperty, value); }
}
Public Shared ReadOnly CurrentReadingProperty As DependencyProperty =
    DependencyProperty.Register("CurrentReading",
        GetType(Double), GetType(Gauge),
        New FrameworkPropertyMetadata(Double.NaN,
            FrameworkPropertyMetadataOptions.AffectsMeasure,
            New PropertyChangedCallback(AddressOf OnCurrentReadingChanged),
            New CoerceValueCallback(AddressOf CoerceCurrentReading)),
        New ValidateValueCallback(AddressOf IsValidReading))

Public Property CurrentReading() As Double
    Get
        Return CDbl(GetValue(CurrentReadingProperty))
    End Get
    Set(ByVal value As Double)
        SetValue(CurrentReadingProperty, value)
    End Set
End Property

備註

如需相依性屬性註冊的詳細資訊,請參閱 DependencyProperty

另請參閱

適用於