信息
您所需的主题如下所示。但此主题未包含在此库中。

DependencyObject 类

Represents an object that participates in the dependency property system.

命名空间: System.Windows
程序集: WindowsBase(在 windowsbase.dll 中)
XML 命名空间:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[TypeDescriptionProviderAttribute(typeof(DependencyObjectProvider))] 
public class DependencyObject : DispatcherObject
/** @attribute TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider) */ 
public class DependencyObject extends DispatcherObject
TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider) 
public class DependencyObject extends DispatcherObject
<DependencyObject .../>

The DependencyObject class enables 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. Another key class that participates in the property system is DependencyPropertyDependencyProperty enables the registration of dependency properties into the property system, and provides information about them, whereas DependencyObject enables objects to use the dependency properties.

DependencyObject services and characteristics include the following:

  • Dependency property hosting support. 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. You register an attached property by calling the RegisterAttached method, and storing the method's return value as a public static readonly field in your class. (There are also additional member requirements; for details, see Attached Properties Overview).Your attached property can then be set on any class that derives from 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. Also, the DependencyObject class facilitates the per-owner property metadata for a dependency property.

  • A common base class for classes derived from ContentElement, Freezable, or Visual. (UIElement, the other core element class, is a deeper subclass of Visual.)

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);
    }
}

System.Object
   System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
       派生类

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

.NET Framework

受以下版本支持:3.0

社区附加资源

显示:
© 2015 Microsoft