DependencyProperty.Name 属性

定义

获取依赖属性的名称。Gets the name of the dependency property.

public:
 property System::String ^ Name { System::String ^ get(); };
public string Name { get; }
member this.Name : string
Public ReadOnly Property Name As String

属性值

属性的名称。The name of the property.

示例

下面的示例查询依赖属性标识符的各种特征,包括 NameThe following example queries various characteristics of a dependency property identifier, including the Name.

pm = dp.GetMetadata(dp.OwnerType);
MetadataClass.Text = pm.GetType().Name;
TypeofPropertyValue.Text = dp.PropertyType.Name;
DefaultPropertyValue.Text = (pm.DefaultValue!=null) ? pm.DefaultValue.ToString() : "null";
HasCoerceValue.Text = (pm.CoerceValueCallback == null) ? "No" : pm.CoerceValueCallback.Method.Name;
HasPropertyChanged.Text = (pm.PropertyChangedCallback == null) ? "No" : pm.PropertyChangedCallback.Method.Name;
ReadOnly.Text = (dp.ReadOnly) ? "Yes" : "No";
pm = dp.GetMetadata(dp.OwnerType)
MetadataClass.Text = pm.GetType().Name
TypeofPropertyValue.Text = dp.PropertyType.Name
DefaultPropertyValue.Text = If((pm.DefaultValue IsNot Nothing), pm.DefaultValue.ToString(), "null")
HasCoerceValue.Text = If((pm.CoerceValueCallback Is Nothing), "No", pm.CoerceValueCallback.Method.Name)
HasPropertyChanged.Text = If((pm.PropertyChangedCallback Is Nothing), "No", pm.PropertyChangedCallback.Method.Name)
    [ReadOnly].Text = If((dp.ReadOnly), "Yes", "No")

注解

此属性获取在依赖项属性注册过程中作为 name 参数提供的名称。This property gets the name provided as the name parameter during dependency property registration. 此名称是不可变的,不能 null 或空字符串。This name is immutable, and cannot be null or an empty string. 不允许在同一所有者类型上进行重复的名称注册,并且当你尝试注册重复时,将引发异常。Duplicate name registrations on the same owner type are not permitted, and will throw an exception when you attempt to register the duplicate.

重要

依赖项属性的 Name 必须遵循与其依赖项属性标识符的名称相匹配的约定,而不是后缀 "Property"。The Name of a dependency property must follow the convention of matching the name of its dependency property identifier minus the suffix "Property". 有关详细信息,请参阅自定义依赖属性For details, see Custom Dependency Properties.

适用于

另请参阅