DependencyProperty.AddOwner DependencyProperty.AddOwner DependencyProperty.AddOwner DependencyProperty.AddOwner Method

定義

加入其他類型,以作為已註冊至某個類型之相依性屬性的擁有者。Adds another type as an owner of a dependency property that has already been registered to a type.

多載

AddOwner(Type) AddOwner(Type) AddOwner(Type) AddOwner(Type)

加入其他類型,作為已註冊之相依性屬性的擁有者。Adds another type as an owner of a dependency property that has already been registered.

AddOwner(Type, PropertyMetadata) AddOwner(Type, PropertyMetadata) AddOwner(Type, PropertyMetadata) AddOwner(Type, PropertyMetadata)

加入另一個類型作為已註冊的相依性屬性的擁有者,並提供在所提供擁有者類型上存在之相依性屬性的相依性屬性中繼資料。Adds another type as an owner of a dependency property that has already been registered, providing dependency property metadata for the dependency property as it will exist on the provided owner type.

AddOwner(Type) AddOwner(Type) AddOwner(Type) AddOwner(Type)

加入其他類型,作為已註冊之相依性屬性的擁有者。Adds another type as an owner of a dependency property that has already been registered.

public:
 System::Windows::DependencyProperty ^ AddOwner(Type ^ ownerType);
public System.Windows.DependencyProperty AddOwner (Type ownerType);
member this.AddOwner : Type -> System.Windows.DependencyProperty
Public Function AddOwner (ownerType As Type) As DependencyProperty

參數

ownerType
Type Type Type Type

要加入為此相依性屬性之擁有者的類型。The type to add as an owner of this dependency property.

傳回

原始 DependencyProperty 識別項的參考,它識別相依性屬性。A reference to the original DependencyProperty identifier that identifies the dependency property. 應該藉由加入類別作為 public static readonly 欄位來公開此識別項。This identifier should be exposed by the adding class as a public static readonly field.

備註

這個方法可讓屬性系統在一開始不會註冊該特定相依性屬性的類型上辨識相依性屬性。This method enables the property system to recognize a dependency property on a type that did not register that particular dependency property initially.

一般來說, AddOwner是用來將相依性屬性新增至尚未透過 managed 類別繼承公開該相依性屬性的類別 (類別繼承會導致衍生類別繼承包裝函式屬性, 因此會提供一般成員-相依性屬性的資料表存取權。Typically, AddOwner is used to add dependency properties to classes that do not already expose that dependency property through managed class inheritance (class inheritance would cause the wrapper properties to be inherited by the derived class, and thus would provide general members-table access to the dependency property already). AddOwner讓屬性系統在一開始不註冊該相依性屬性的類型上辨識相依性屬性。AddOwner enables the property system to recognize a dependency property on a type that did not register that dependency property initially.

此簽章不允許指定中繼資料。This signature does not allow for specifying metadata. 當您使用這個方法時, 會自動產生新DependencyProperty的和其擁有者類型的中繼資料。When you use this method, the metadata is automatically generated for the new DependencyProperty and its owner type. 自動產生的中繼資料是來自已定義此屬性之所有基底類型中合併中繼資料的結果。The auto-generated metadata is the result of the merged metadata from all of the base types that have this property defined. 如果沒有合併的中繼資料可用, 則會使用屬性的預設中繼資料。If no merged metadata is available, then the default metadata for the property is used. 如果使用RegisterAttached方法註冊屬性, 則預設的中繼資料會與呼叫時RegisterAttached所建立的中繼資料相同。If the property is registered by using the RegisterAttached method, then the default metadata is the same as the metadata that is created when RegisterAttached was called. 否則, PropertyMetadataDefaultValue建立物件, 並將屬性設定為屬性類型的預設值, 並將的PropertyMetadata所有其他屬性設為nullOtherwise, the PropertyMetadata object is created with the DefaultValue property set to the property type's default and all other properties of the PropertyMetadata is set to null. AddOwner(Type, PropertyMetadata)如果您想要提供相依性屬性版本的中繼資料 (加入至提供的類型), 請使用簽章。Use the AddOwner(Type, PropertyMetadata) signature if you want to provide metadata for the version of the dependency property as added to the provided type.

這個方法的傳回值通常是用來透過儲存相依性屬性識別碼來宣告和公開相依性屬性。The return value of this method is typically used to declare and expose the dependency property by storing a dependency property identifier. 如果您想要針對相依性屬性呼叫屬性系統APIAPIs , 則識別碼會提供相依性屬性的存取權, 特別是存在於加入擁有者類別時。The identifier provides access to the dependency property if you want to call property system APIAPIs against the dependency property, particularly as it exists on the adding owner class. 原始擁有者和加入的擁有者都應該使用相同的屬性名稱來表示類似的功能。The same property name for both original owner and added owner should be used to indicate the similar functionality. 您應該使用AddOwner方法DependencyProperty的傳回值來定義相依性屬性識別碼CLRCLR , 也可以宣告屬性包裝函式, 以使用AddOwner加入至類型的相依性屬性。You should use the DependencyProperty return value of the AddOwner method to define the dependency property identifier, and also to declare CLRCLR property wrappers, for dependency properties that are added to types using AddOwner.

AddOwner建立內WPFWPF宣告的相依性屬性時, 會使用上述的方法建議。The AddOwner methodology recommended above is used when creating the dependency properties that are declared within WPFWPF. 例如, 和Control都會Border定義BorderBrush具有類似功能的相依性屬性。For instance, both Border and Control define a BorderBrush dependency property, which have similar functionality. Control藉由BorderBrush呼叫AddOwner以原始擁有Border者和其已註冊BorderBrushProperty的相依性屬性識別碼為基礎, 將其屬性定義為屬性系統。Control defines its BorderBrush property to the property system by calling AddOwner based on the original owner Border and its registered BorderBrushProperty dependency property identifer. 接著會使用傳回值, 在加入的擁有者DependencyProperty上建立BorderBrushPropertyBorderBrush屬性的新靜態欄位 (), 而且也會宣告屬性包裝函式。 AddOwnerThe AddOwner return value is then used to establish a new static DependencyProperty field (BorderBrushProperty) for that property on the added owner, and a BorderBrush property wrapper is also declared.

AddOwner(Type, PropertyMetadata) AddOwner(Type, PropertyMetadata) AddOwner(Type, PropertyMetadata) AddOwner(Type, PropertyMetadata)

加入另一個類型作為已註冊的相依性屬性的擁有者,並提供在所提供擁有者類型上存在之相依性屬性的相依性屬性中繼資料。Adds another type as an owner of a dependency property that has already been registered, providing dependency property metadata for the dependency property as it will exist on the provided owner type.

public:
 System::Windows::DependencyProperty ^ AddOwner(Type ^ ownerType, System::Windows::PropertyMetadata ^ typeMetadata);
public System.Windows.DependencyProperty AddOwner (Type ownerType, System.Windows.PropertyMetadata typeMetadata);
member this.AddOwner : Type * System.Windows.PropertyMetadata -> System.Windows.DependencyProperty
Public Function AddOwner (ownerType As Type, typeMetadata As PropertyMetadata) As DependencyProperty

參數

ownerType
Type Type Type Type

要加入為此相依性屬性之擁有者的類型。The type to add as owner of this dependency property.

typeMetadata
PropertyMetadata PropertyMetadata PropertyMetadata PropertyMetadata

限定存在於所提供類型之相依性屬性的中繼資料。The metadata that qualifies the dependency property as it exists on the provided type.

傳回

原始 DependencyProperty 識別項的參考,它識別相依性屬性。A reference to the original DependencyProperty identifier that identifies the dependency property. 應該藉由加入類別作為 public static readonly 欄位來公開此識別項。This identifier should be exposed by the adding class as a public static readonly field.

備註

這個方法可讓屬性系統在一開始不會註冊該特定相依性屬性的類型上辨識相依性屬性。This method enables the property system to recognize a dependency property on a type that did not register that particular dependency property initially.

這個方法的傳回值是用來宣告和公開相依性屬性, 特別是它存在於新增擁有者類別上。The return value of this method is used to declare and expose the dependency property, particularly as it exists on the adding owner class. 一般來說, 原始擁有者和加入的擁有者都應該使用相同的屬性名稱來表示類似的功能。Generally, the same property name for both original owner and added owner should be used to indicate the similar functionality. CLRCLR 使用AddOwner將加入至類型的相依性屬性公開識別碼, 以及新的屬性包裝函式是很好的作法。It is good practice to expose the identifiers, as well as new CLRCLR property wrappers, for dependency properties that are added to types using AddOwner.

AddOwner APIAPIs內建立WPFWPF宣告時, 會使用上述建議的方法。The AddOwner methodology recommended above is used when creating APIAPIs declared within WPFWPF. 例如, 和Control都會Border定義BorderBrush具有類似功能的相依性屬性。For instance, both Border and Control define a BorderBrush dependency property, which have similar functionality. Control藉由BorderBrush呼叫AddOwner原始擁有Border者及其已註冊BorderBrushProperty的相依性屬性識別碼, 將其屬性定義為屬性系統。Control defines its BorderBrush property to the property system by calling AddOwner on original owner Border and its registered BorderBrushProperty dependency property identifer. 接著會使用傳回值, 在加入的擁有DependencyProperty者上BorderBrushProperty建立該BorderBrush屬性的靜態欄位 (), 而且也會宣告屬性包裝函式。 AddOwnerThe AddOwner return value is then used to establish a static DependencyProperty field (BorderBrushProperty) for that property on the added owner, and a BorderBrush property wrapper is also declared.

所加入之擁有者的相依性屬性識別碼應用於之類的GetValue作業。The added owner's dependency property identifier should be used for operations such as GetValue. 不過, 涉及已加入為具有不同中繼資料之擁有者的類型或實例的類型特定作業仍會傳回預期的結果, 即使原始 (而非新增的擁有者) 相依性屬性識別碼指定于呼叫GetValueGetMetadata之類的方法。However, type-specific operations involving either types or instances of the class that was added as owner with different metadata will still return the expected results even if the original (not the added owner's) dependency property identifier is specified in calls to methods such as GetValue or GetMetadata. 新增之擁有者的中繼資料是由AddOwner呼叫本身所 perpetuated, 不一定是由 [新增擁有者類別識別碼] 欄位獨佔參考。The metadata for the added owner is perpetuated by the AddOwner call itself, not necessarily referenced exclusively by the adding owner class identifier field. 不過, 使用AddOwner新增至類型的相依性屬性, 也可以公開識別碼CLRCLR和新的屬性包裝函式, 因為無法執行此動作會在CLRCLR和之間建立差異XAMLXAML屬性的標記法。Nevertheless, it is good practice to expose the identifier, as well as new CLRCLR property wrappers, for dependency properties that are added to types using AddOwner, because failing to do so creates disparity between the CLRCLR and XAMLXAML representations of your properties.

提供的中繼資料會與相依性屬性的屬性中繼資料合併, 因為它存在於基底擁有者上。The supplied metadata is merged with the property metadata for the dependency property as it exists on the base owner. 原始基底中繼資料中指定的任何特性都會保存。Any characteristics that were specified in the original base metadata will persist. 只有在新的中繼資料中特別變更的特性, 才會覆寫基底中繼資料的特性。Only those characteristics that were specifically changed in the new metadata will override the characteristics of the base metadata. 某些特性 (例如DefaultValue) 會在新的中繼資料中指定時予以取代。Some characteristics, such as DefaultValue, are replaced if they are specified in the new metadata. 其他專案 (例如PropertyChangedCallback) 則結合在一起。Others, such as PropertyChangedCallback, are combined. 最後, 合併行為取決於用於覆寫的屬性元資料類型, 因此這裡所述的行為適用于相依性屬性所使用WPFWPF的現有屬性中繼資料類別。Ultimately, the merge behavior depends on the property metadata type being used for the override, so the behavior described here is for the existing property metadata classes used by WPFWPF dependency properties. 如需詳細資訊, 請參閱相依性屬性中繼資料架構屬性中繼資料For details, see Dependency Property Metadata and Framework Property Metadata.

適用於