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

備註

類別會在Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF)其許多衍生類別上啟用屬性系統服務。 DependencyObjectThe 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. 如需詳細資訊, 請參閱附加屬性總覽。)然後您可以在任何衍生自DependencyObject的類別上設定附加屬性。For details, see Attached Properties Overview.) Your attached property can then be set on any class that derives from DependencyObject.

  • 針對存在於上DependencyObject的任何相依性屬性的值, 取得、設定和清除公用程式方法。Get, 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.

  • 衍生自、 ContentElement FreezableVisual之類別的通用基類。A 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

取得與這個 Dispatcher 關聯的 DispatcherObjectGets 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 的淺層複本 (Shallow Copy)。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()

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

(Inherited from DispatcherObject)

適用於

另請參閱