DependencyObject DependencyObject DependencyObject DependencyObject Class

定義

表示參與相依性屬性系統的物件。Represents an object that participates in the dependency property system.

public ref class DependencyObject : System::Windows::Threading::DispatcherObject
[System.Windows.Markup.NameScopeProperty("NameScope", typeof(System.Windows.NameScope))]
public class DependencyObject : System.Windows.Threading.DispatcherObject
type DependencyObject = class
    inherit DispatcherObject
Public Class DependencyObject
Inherits DispatcherObject
繼承
DependencyObjectDependencyObjectDependencyObjectDependencyObject
衍生
屬性

範例

下列範例衍生自DependencyObject來建立新的抽象類別。The following example derives from DependencyObject to create a new abstract class. 然後,此類別註冊附加的屬性,而且包含該附加屬性的支援成員。The class then registers an attached property and includes support members for that attached property.

public abstract class AquariumObject3 : DependencyObject
{
    public enum Bouyancy
    {
        Floats,
        Sinks,
        Drifts
    }
    public static readonly DependencyProperty BouyancyProperty = DependencyProperty.RegisterAttached(
      "Bouyancy",
      typeof(Bouyancy),
      typeof(AquariumObject3),
      new FrameworkPropertyMetadata(Bouyancy.Floats, FrameworkPropertyMetadataOptions.AffectsArrange),
      new ValidateValueCallback(ValidateBouyancy)
    );
    public static void SetBouyancy(UIElement element, Bouyancy value)
    {
        element.SetValue(BouyancyProperty, value);
    }
    public static Bouyancy GetBouyancy(UIElement element)
    {
        return (Bouyancy)element.GetValue(BouyancyProperty);
    }
    private static bool ValidateBouyancy(object value)
    {
        Bouyancy bTest = (Bouyancy) value;
        return (bTest == Bouyancy.Floats || bTest == Bouyancy.Drifts || bTest==Bouyancy.Sinks);
    }
    public static readonly DependencyProperty IsDirtyProperty = DependencyProperty.Register(
      "IsDirty",
      typeof(Boolean),
      typeof(AquariumObject3)
    );
}
Public MustInherit Class AquariumObject3
    Inherits DependencyObject
    Public Enum Bouyancy
        Floats
        Sinks
        Drifts
    End Enum
    Public Shared ReadOnly BouyancyProperty As DependencyProperty = DependencyProperty.RegisterAttached("Bouyancy", GetType(Bouyancy), GetType(AquariumObject3), New FrameworkPropertyMetadata(Bouyancy.Floats, FrameworkPropertyMetadataOptions.AffectsArrange), New ValidateValueCallback(AddressOf ValidateBouyancy))
    Public Shared Sub SetBouyancy(ByVal element As UIElement, ByVal value As Bouyancy)
        element.SetValue(BouyancyProperty, value)
    End Sub
    Public Shared Function GetBouyancy(ByVal element As UIElement) As Bouyancy
        Return CType(element.GetValue(BouyancyProperty), Bouyancy)
    End Function
    Private Shared Function ValidateBouyancy(ByVal value As Object) As Boolean
        Dim bTest As Bouyancy = CType(value, Bouyancy)
        Return (bTest = Bouyancy.Floats OrElse bTest = Bouyancy.Drifts OrElse bTest = Bouyancy.Sinks)
    End Function
    Public Shared ReadOnly IsDirtyProperty As DependencyProperty = DependencyProperty.Register("IsDirty", GetType(Boolean), GetType(AquariumObject3))
End Class

備註

DependencyObject類別可讓Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF)屬性系統服務在其許多的衍生類別。The DependencyObject class enables Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) property system services on its many derived classes.

屬性系統的主要功能是以計算屬性的值,並提供系統通知有關已變更的值。The property system's primary function is to compute the values of properties, and to provide system notification about values that have changed. 參與屬性系統的另一個索引鍵類別是DependencyPropertyAnother key class that participates in the property system is DependencyProperty. DependencyProperty 屬性系統,讓相依性屬性的註冊,並提供識別與每個相依性屬性的相關資訊,而DependencyObject因為基底類別可讓使用相依性屬性的物件。DependencyProperty enables the registration of dependency properties into the property system, and provides identification and information about each dependency property, whereas DependencyObject as a base class enables objects to use the dependency properties.

DependencyObject 服務和特性包括:DependencyObject services and characteristics include the following:

  • 裝載支援的相依性屬性。Dependency property hosting support. 藉由呼叫註冊相依性屬性Register方法,並將方法的傳回值儲存為您的類別中公用靜態欄位。You register a dependency property by calling the Register method, and storing the method's return value as a public static field in your class.

  • 裝載支援的附加的屬性。Attached property hosting support. 藉由呼叫註冊附加的屬性RegisterAttached方法,並將方法的傳回值儲存為公用靜態唯讀欄位在您的類別。You register an attached property by calling the RegisterAttached method, and storing the method's return value as a public static read-only field in your class. (另外還有其他成員的需求,請注意,這代表WPFWPF附加屬性的特定實作。(There are also additional member requirements; note that this represents a WPFWPF specific implementation for attached properties. 如需詳細資訊,請參閱 < 附加屬性概觀。)然後可以將附加的屬性設定任何衍生自的類別上DependencyObjectFor details, see Attached Properties Overview.) Your attached property can then be set on any class that derives from DependencyObject.

  • Get、 set 和清除公用程式方法存在於任何相依性屬性的值, DependencyObjectGet, set, and clear utility methods for values of any dependency properties that exist on the DependencyObject.

  • 中繼資料,強制轉型值支援、 屬性變更通知,以及覆寫相依性屬性回呼,或附加的屬性。Metadata, coerce value support, property changed notification, and override callbacks for dependency properties or attached properties. 此外,DependencyObject類別有助於相依性屬性的每個擁有者屬性中繼資料。Also, the DependencyObject class facilitates the per-owner property metadata for a dependency property.

  • 類別的通用基底類別衍生自ContentElementFreezable,或VisualA common base class for classes derived from ContentElement, Freezable, or Visual. (UIElement,另一個基底項目類別,已包含的類別階層Visual。)(UIElement, another base element class, has a class hierarchy that includes Visual.)

建構函式

DependencyObject() DependencyObject() DependencyObject() DependencyObject()

初始化 DependencyObject 類別的新執行個體。Initializes a new instance of the DependencyObject class.

屬性

DependencyObjectType DependencyObjectType DependencyObjectType DependencyObjectType

取得包裝此執行個體之 CLRCLR 型別的 DependencyObjectTypeGets the DependencyObjectType that wraps the CLRCLR type of this instance.

Dispatcher Dispatcher Dispatcher Dispatcher

取得DispatcherDispatcherObject相關聯。Gets the Dispatcher this DispatcherObject is associated with.

(Inherited from DispatcherObject)
IsSealed IsSealed IsSealed IsSealed

取得值,這個值表示此執行個體目前是否已密封 (唯讀)。Gets a value that indicates whether this instance is currently sealed (read-only).

方法

CheckAccess() CheckAccess() CheckAccess() CheckAccess()

判斷呼叫的執行緒是否可以存取這個DispatcherObjectDetermines whether the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty)

清除屬性的區域數值。Clears the local value of a property. 要清除的屬性是由 DependencyProperty 識別項所指定。The property to be cleared is specified by a DependencyProperty identifier.

ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey)

清除唯讀屬性的區域數值。Clears the local value of a read-only property. 要清除的屬性是由 DependencyPropertyKey 所指定。The property to be cleared is specified by a DependencyPropertyKey.

CoerceValue(DependencyProperty) CoerceValue(DependencyProperty) CoerceValue(DependencyProperty) CoerceValue(DependencyProperty)

強制轉型所指定相依性屬性的值。Coerces the value of the specified dependency property. 叫用存在於呼叫 CoerceValueCallback 上相依性屬性之屬性中繼資料內所指定的任何 DependencyObject 函式,就可以達到這一點。This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷提供的 DependencyObject 和目前的 DependencyObject 是否相等。Determines whether a provided DependencyObject is equivalent to the current DependencyObject.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

取得這個 DependencyObject 的雜湊程式碼。Gets a hash code for this DependencyObject.

GetLocalValueEnumerator() GetLocalValueEnumerator() GetLocalValueEnumerator() GetLocalValueEnumerator()

建立特定的列舉值,以判斷哪些相依性屬性在此 DependencyObject 上具有本機設定的值。Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty)

傳回 DependencyObject 的這個執行個體上之相依性屬性的目前有效值。Returns the current effective value of a dependency property on this instance of a DependencyObject.

InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty)

重新評估指定之相依性屬性的有效值。Re-evaluates the effective value for the specified dependency property

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(Inherited from Object)
OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs)

每當這個 DependencyObject 上任何相依性屬性的有效值已更新時叫用。Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. 已變更的特定相依性屬性會在事件資料中報告。The specific dependency property that changed is reported in the event data.

ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty)

傳回相依性屬性的區域值 (如果存在)。Returns the local value of a dependency property, if it exists.

SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object)

設定相依性屬性的值,而不需要變更其值來源。Sets the value of a dependency property without changing its value source.

SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object)

設定相依性屬性的區域值 (由相依性屬性的識別碼所指定)。Sets the local value of a dependency property, specified by its dependency property identifier.

SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object)

設定唯讀相依性屬性的區域數值 (由相依性屬性的 DependencyPropertyKey 識別項所指定)。Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty)

傳回值,這個值表示序列化程序是否應該序列化所提供相依性屬性的值。Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
VerifyAccess() VerifyAccess() VerifyAccess() VerifyAccess()

強制執行呼叫的執行緒可以存取這個DispatcherObjectEnforces that the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)

適用於

另請參閱