DependencyProperty.Register 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注册依赖属性。
重载
| 名称 | 说明 |
|---|---|
| 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。