DependencyProperty.Name DependencyProperty.Name DependencyProperty.Name DependencyProperty.Name Property

定義

取得相依性屬性的名稱。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.

適用於

另請參閱