依赖属性概述Dependency properties overview

Windows Presentation Foundation (WPF) 提供一组服务,这些服务可用于扩展类型的属性的功能。Windows Presentation Foundation (WPF) provides a set of services that can be used to extend the functionality of a type's property. 这些服务通常统称为 WPF 属性系统。Collectively, these services are typically referred to as the WPF property system. 由 WPF 属性系统支持的属性称为依赖属性。A property that is backed by the WPF property system is known as a dependency property. 本概述介绍 WPF 属性系统以及依赖属性的功能。This overview describes the WPF property system and the capabilities of a dependency property. 这包括如何在 XAML 和在代码中使用现有依赖属性。This includes how to use existing dependency properties in XAML and in code. 本概述还介绍依赖属性所特有的方面(如依赖属性元数据),并说明如何在自定义类中创建自己的依赖属性。This overview also introduces specialized aspects of dependency properties, such as dependency property metadata, and how to create your own dependency property in a custom class.

PrerequisitesPrerequisites

本主题假设你在 .NET 类型系统和面向对象的编程方面有一些基础知识。This topic assumes that you have some basic knowledge of the .NET type system and object-oriented programming. 为了能理解本主题中的示例,还应了解 XAML 并知道如何编写 WPF 应用程序。In order to follow the examples in this topic, you should also understand XAML and know how to write WPF applications. 有关详细信息,请参阅演练:我的第一个 WPF 桌面应用程序For more information, see Walkthrough: My first WPF desktop application.

依赖属性和 CLR 属性Dependency properties and CLR properties

在 WPF 中,属性通常公开为标准 .NET 属性In WPF, properties are typically exposed as standard .NET properties. 在基本级别,可以直接与这些属性交互,而不必了解它们是以依赖属性的形式实现的。At a basic level, you could interact with these properties directly and never know that they are implemented as a dependency property. 但是,应当熟悉 WPF 属性系统的部分或全部功能,以便利用这些功能。However, you should become familiar with some or all of the features of the WPF property system, so that you can take advantage of these features.

依赖属性的用途在于提供一种方法来基于其他输入的值计算属性值。The purpose of dependency properties is to provide a way to compute the value of a property based on the value of other inputs. 这些其他输入可能包括系统属性(如主题和用户首选项)、实时属性确定机制(如数据绑定和动画/情节提要)、重用模板(如资源和样式)或者通过与元素树中其他元素的父子关系来公开的值。These other inputs might include system properties such as themes and user preference, just-in-time property determination mechanisms such as data binding and animations/storyboards, multiple-use templates such as resources and styles, or values known through parent-child relationships with other elements in the element tree. 另外,可以通过实现依赖属性来提供独立验证、默认值、监视其他属性的更改的回叫以及可以基于可能的运行时信息来强制指定属性值的系统。In addition, a dependency property can be implemented to provide self-contained validation, default values, callbacks that monitor changes to other properties, and a system that can coerce property values based on potentially runtime information. 派生类还可以通过重写依赖属性元数据(而不是重写现有属性的实际实现或者创建新属性)来更改现有属性的某些具体特征。Derived classes can also change some specific characteristics of an existing property by overriding dependency property metadata, rather than overriding the actual implementation of existing properties or creating new properties.

在 SDK 参考中,可以根据某个属性的托管引用页上是否存在“依赖属性信息”部分来确定该属性是否为依赖属性。In the SDK reference, you can identify which property is a dependency property by the presence of the Dependency Property Information section on the managed reference page for that property. “依赖属性信息”部分包括一个指向该依赖属性的 DependencyProperty 标识符字段的链接,还包括一个为该属性设置的元数据选项列表、每个类的重写信息以及其他详细信息。The Dependency Property Information section includes a link to the DependencyProperty identifier field for that dependency property, and also includes a list of the metadata options that are set for that property, per-class override information, and other details.

依赖属性支持 CLR 属性Dependency properties back CLR properties

依赖属性和 WPF 属性系统通过提供一个支持属性的类型来扩展属性功能,这是使用专用字段支持该属性的标准模式的替代实现方法。Dependency properties and the WPF property system extend property functionality by providing a type that backs a property, as an alternative implementation to the standard pattern of backing the property with a private field. 此类型的名称为 DependencyPropertyThe name of this type is DependencyProperty. 定义 WPF 属性系统的另一个重要类型是 DependencyObjectThe other important type that defines the WPF property system is DependencyObject. DependencyObject 定义可以注册和拥有依赖属性的基类。DependencyObject defines the base class that can register and own a dependency property.

下面列出了与依赖属性一起使用的术语:The following lists the terminology that is used with dependency properties:

  • 依赖属性: DependencyProperty 支持的属性。Dependency property: A property that is backed by a DependencyProperty.

  • 依赖属性标识符: 一个 DependencyProperty 实例,在注册依赖属性时以返回值形式获取它,之后将其存储为类的静态成员。Dependency property identifier: A DependencyProperty instance, which is obtained as a return value when registering a dependency property, and then stored as a static member of a class. 对于与 WPF 属性系统交互的许多 API,此标识符用作一个参数。This identifier is used as a parameter for many of the APIs that interact with the WPF property system.

  • CLR“包装器”: 属性的实际 get 和 set 实现。CLR "wrapper": The actual get and set implementations for the property. 这些实现通过在 GetValueSetValue 调用中使用依赖属性标识符来并入依赖属性标识符,从而使用 WPF 属性系统为属性提供支持。These implementations incorporate the dependency property identifier by using it in the GetValue and SetValue calls, thus providing the backing for the property using the WPF property system.

下面的示例定义 IsSpinning 依赖属性,并说明 DependencyProperty 标识符与它所支持的属性之间的关系。The following example defines the IsSpinning dependency property, and shows the relationship of the DependencyProperty identifier to the property that it backs.

public static readonly DependencyProperty IsSpinningProperty = 
    DependencyProperty.Register(
    "IsSpinning", typeof(Boolean),
    typeof(MyCode)
    );
public bool IsSpinning
{
    get { return (bool)GetValue(IsSpinningProperty); }
    set { SetValue(IsSpinningProperty, value); }
}
Public Shared ReadOnly IsSpinningProperty As DependencyProperty =
    DependencyProperty.Register("IsSpinning",
                                GetType(Boolean),
                                GetType(MyCode))

Public Property IsSpinning() As Boolean
    Get
        Return CBool(GetValue(IsSpinningProperty))
    End Get
    Set(ByVal value As Boolean)
        SetValue(IsSpinningProperty, value)
    End Set
End Property

属性及其支持性 DependencyProperty 字段的命名约定非常重要。The naming convention of the property and its backing DependencyProperty field is important. 字段总是与属性同名,但其后面追加了 Property 后缀。The name of the field is always the name of the property, with the suffix Property appended. 有关此约定及其原因的详细信息,请参阅自定义依赖属性For more information about this convention and the reasons for it, see Custom Dependency Properties.

设置属性值Setting property values

可以在代码或 XAML 中设置属性。You can set properties either in code or in XAML.

在 XAML 中设置属性值Setting property values in XAML

下面的 XAML 示例将按钮的背景色指定为红色。The following XAML example specifies the background color of a button as red. 此示例演示这样一种情况:在所生成的代码中,WPF XAML 分析器将 XAML 属性的简单字符串值类型转换为 WPF 类型(一个 Color,通过 SolidColorBrush 实现)。This example illustrates a case where the simple string value for a XAML attribute is type-converted by the WPF XAML parser into a WPF type (a Color, by way of a SolidColorBrush) in the generated code.

<Button Background="Red" Content="Button!"/>

XAML 支持多种设置属性的语法格式。XAML supports a variety of syntax forms for setting properties. 要对特定的属性使用哪种语法取决于该属性所使用的值类型以及其他因素(例如,是否存在类型转换器)。Which syntax to use for a particular property will depend on the value type that a property uses, as well as other factors such as the presence of a type converter. 有关属性设置的 XAML 语法的详细信息,请参阅 XAML 概述 (WPF)XAML 语法详述For more information on XAML syntax for property setting, see XAML Overview (WPF) and XAML Syntax In Detail.

作为非属性语法的示例,下面的 XAML 示例显示了另一种按钮背景。As an example of non-attribute syntax, the following XAML example shows another button background. 这一次不是设置简单的纯色,而是将背景设置为图像,用一个元素表示该图像并将该图像的源指定为嵌套元素的属性。This time rather than setting a simple solid color, the background is set to an image, with an element representing that image and the source of that image specified as an attribute of the nested element. 这是属性元素语法的示例。This is an example of property element syntax.

<Button Content="Button!">
  <Button.Background>
    <ImageBrush ImageSource="wavy.jpg"/>
  </Button.Background>
</Button>

在代码中设置属性Setting properties in code

在代码中设置依赖属性值通常只是对 CLR "包装" 公开的集实现的调用。Setting dependency property values in code is typically just a call to the set implementation exposed by the CLR "wrapper".

Button myButton = new Button();
myButton.Width = 200.0;
Dim myButton As New Button()
myButton.Width = 200.0

获取属性值实质上也是在调用 get“包装器”实现:Getting a property value is also essentially a call to the get "wrapper" implementation:

double whatWidth;
whatWidth = myButton.Width;
Dim whatWidth As Double
whatWidth = myButton.Width

你还可以调用属性系统 Api GetValue 并直接 SetValueYou can also call the property system APIs GetValue and SetValue directly. 如果使用现有属性(包装更方便,并为开发人员工具提供更好的属性公开),则通常不需要这样做,但在某些情况下,可以直接调用 Api。This is not typically necessary if you are using existing properties (the wrappers are more convenient, and provide better exposure of the property for developer tools), but calling the APIs directly is appropriate for certain scenarios.

还可以在 XAML 中设置属性,然后通过代码隐藏在代码中访问这些属性。Properties can be also set in XAML and then accessed later in code, through code-behind. 有关详细信息,请参阅 WPF 中的代码隐藏和 XAMLFor details, see Code-Behind and XAML in WPF.

由依赖属性提供的属性功能Property functionality provided by a dependency property

依赖属性提供用来扩展属性功能的功能,这与字段支持的属性相反。A dependency property provides functionality that extends the functionality of a property as opposed to a property that is backed by a field. 通常,此类功能代表或支持以下特定功能之一:Often, such functionality represents or supports one of the following specific features:

资源Resources

依赖属性值可以通过引用资源来设置。A dependency property value can be set by referencing a resource. 资源通常指定为页面根元素或应用程序的 Resources 属性值(通过这些位置可以非常方便地访问资源)。Resources are typically specified as the Resources property value of a page root element, or of the application (these locations enable the most convenient access to the resource). 以下示例演示如何定义 SolidColorBrush 资源。The following example shows how to define a SolidColorBrush resource.

<DockPanel.Resources>
  <SolidColorBrush x:Key="MyBrush" Color="Gold"/>
</DockPanel.Resources>

在定义该资源之后,可以引用该资源并使用它来提供属性值:Once the resource is defined, you can reference the resource and use it to provide a property value:

<Button Background="{DynamicResource MyBrush}" Content="I am gold" />

这个特定资源称为 DynamicResource 标记扩展(在 WPF XAML 中,可以使用静态或动态资源引用)。This particular resource is referenced as a DynamicResource Markup Extension (in WPF XAML, you can use either a static or dynamic resource reference). 若要使用动态资源引用,必须设置为依赖属性,因此它专门是由 WPF 属性系统启用的动态资源引用用法。To use a dynamic resource reference, you must be setting to a dependency property, so it is specifically the dynamic resource reference usage that is enabled by the WPF property system. 有关详细信息,请参阅 XAML 资源For more information, see XAML Resources.

备注

资源被视为本地值,这意味着,如果设置另一个本地值,该资源引用将被消除。Resources are treated as a local value, which means that if you set another local value, you will eliminate the resource reference. 有关详细信息,请参阅依赖属性值优先级For more information, see Dependency Property Value Precedence.

数据绑定Data binding

依赖属性可以通过数据绑定来引用值。A dependency property can reference a value through data binding. 数据绑定通过特定标记扩展语法(在 XAML 中)或 Binding 对象(在代码中)起作用。Data binding works through a specific markup extension syntax in XAML, or the Binding object in code. 使用数据绑定,最终属性值的确定将延迟到运行时,在运行时,将从数据源获取属性值。With data binding, the final property value determination is deferred until run time, at which time the value is obtained from a data source.

以下示例使用在 XAML 中声明的绑定来设置 ButtonContent 属性。The following example sets the Content property for a Button, using a binding declared in XAML. 该绑定使用继承的数据上下文和 XmlDataProvider 数据源(未显示)。The binding uses an inherited data context and an XmlDataProvider data source (not shown). 绑定本身通过数据源中的 XPath 指定所需的源属性。The binding itself specifies the desired source property by XPath within the data source.

<Button Content="{Binding XPath=Team/@TeamName}"/>

备注

绑定被视为本地值,这意味着,如果设置另一个本地值,该绑定将被消除。Bindings are treated as a local value, which means that if you set another local value, you will eliminate the binding. 有关详细信息,请参阅依赖属性值优先级For details, see Dependency Property Value Precedence.

为了生成数据绑定操作的 DependencyObject 源属性值的更改通知,依赖属性或 DependencyObject 类本身不支持 INotifyPropertyChangedDependency properties, or the DependencyObject class, do not natively support INotifyPropertyChanged for purposes of producing notifications of changes in DependencyObject source property value for data binding operations. 有关如何创建要用在数据绑定中并且可以向数据绑定目标报告变化的属性的详细信息,请参阅数据绑定概述For more information on how to create properties for use in data binding that can report changes to a data binding target, see Data Binding Overview.

样式Styles

样式和模板是使用依赖属性的两个主要激发方案。Styles and templates are two of the chief motivating scenarios for using dependency properties. 在设置定义应用程序用户界面 (UI)user interface (UI) 的属性时,样式尤其有用。Styles are particularly useful for setting properties that define application 用户界面 (UI)user interface (UI). 在 XAML 中,通常将样式定义为资源。Styles are typically defined as resources in XAML. 样式与属性系统交互,因为它们通常包含特定属性的“资源库”,以及基于另一个属性的实时值更改属性值的“触发器”。Styles interact with the property system because they typically contain "setters" for particular properties, as well as "triggers" that change a property value based on the real-time value for another property.

以下示例创建非常简单的样式(该样式在 Resources 字典中定义,未显示),然后将该样式直接应用于 ButtonStyle 属性。The following example creates a very simple style (which would be defined inside a Resources dictionary, not shown), then applies that style directly to the Style property for a Button. 样式中的资源库将带样式 ButtonBackground 属性设置为绿色。The setter within the style sets the Background property for a styled Button to green.

<Style x:Key="GreenButtonStyle">
  <Setter Property="Control.Background" Value="Green"/>
</Style>
<Button Style="{StaticResource GreenButtonStyle}">I am green!</Button>

有关详细信息,请参阅样式设置和模板化For more information, see Styling and Templating.

动画Animations

可以对依赖属性进行动画处理。Dependency properties can be animated. 在应用和运行动画时,经过动画处理的值的操作优先级高于该属性以其他方式具有的任何值(如本地值)。When an animation is applied and is running, the animated value operates at a higher precedence than any value (such as a local value) that the property otherwise has.

以下示例在 Button 属性上对 Background 进行动画处理(从技术上讲,通过使用属性元素语法将空白 SolidColorBrush 指定为 Background 来对 Background 进行动画处理,然后该 SolidColorBrushColor 属性就是直接动画处理过的属性)。The following example animates the Background on a Button property (technically, the Background is animated by using property element syntax to specify a blank SolidColorBrush as the Background, then the Color property of that SolidColorBrush is the property that is directly animated).

<Button>I am animated
  <Button.Background>
    <SolidColorBrush x:Name="AnimBrush"/>
  </Button.Background>
  <Button.Triggers>
    <EventTrigger RoutedEvent="Button.Loaded">
      <BeginStoryboard>
        <Storyboard>
          <ColorAnimation
            Storyboard.TargetName="AnimBrush" 
            Storyboard.TargetProperty="(SolidColorBrush.Color)"
            From="Red" To="Green" Duration="0:0:5" 
            AutoReverse="True" RepeatBehavior="Forever" />
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Button.Triggers>
</Button>

有关对属性进行动画处理的详细信息,请参阅动画概述情节提要概述For more information on animating properties, see Animation Overview and Storyboards Overview.

元数据重写Metadata overrides

在从最初注册依赖属性的类派生时,可以通过重写依赖属性的元数据来更改该属性的某些行为。You can change certain behaviors of a dependency property by overriding the metadata for that property when you derive from the class that originally registers the dependency property. 重写元数据依赖于 DependencyProperty 标识符。Overriding metadata relies on the DependencyProperty identifier. 重写元数据不需要重新实现属性。Overriding metadata does not require re-implementing the property. 元数据的更改由属性系统在本机处理;对于所有从基类继承的属性,每个类都有可能基于每个类型保留元数据。The metadata change is handled natively by the property system; each class potentially holds individual metadata for all properties that are inherited from base classes, on a per-type basis.

以下示例重写依赖属性 DefaultStyleKey 的元数据。The following example overrides metadata for a dependency property DefaultStyleKey. 重写此特定依赖属性的元数据是某个实现模式的一部分,该模式创建可以使用主题中的默认样式的控件。Overriding this particular dependency property metadata is part of an implementation pattern that creates controls that can use default styles from themes.

public class SpinnerControl : ItemsControl
{
    static SpinnerControl()
    {
        DefaultStyleKeyProperty.OverrideMetadata(
            typeof(SpinnerControl), 
            new FrameworkPropertyMetadata(typeof(SpinnerControl))
        );
    }
}
Public Class SpinnerControl
    Inherits ItemsControl
    Shared Sub New()
        DefaultStyleKeyProperty.OverrideMetadata(GetType(SpinnerControl), New FrameworkPropertyMetadata(GetType(SpinnerControl)))
    End Sub
End Class

有关替代或获取属性元数据的详细信息,请参阅依赖属性元数据For more information about overriding or obtaining property metadata, see Dependency Property Metadata.

属性值继承Property value inheritance

元素可以从其在对象树中的父级继承依赖属性的值。An element can inherit the value of a dependency property from its parent in the object tree.

备注

属性值继承行为并未针对所有依赖属性在全局启用,因为继承的计算时间确实会对性能产生一定的影响。Property value inheritance behavior is not globally enabled for all dependency properties, because the calculation time for inheritance does have some performance impact. 属性值继承通常只有在特定方案指出适合使用属性值继承时才对属性启用。Property value inheritance is typically only enabled for properties where a particular scenario suggests that property value inheritance is appropriate. 可以通过在 SDK 参考中查看某个依赖属性的依赖属性信息部分,来确定该依赖属性是否继承属性值。You can determine whether a dependency property inherits by looking at the Dependency Property Information section for that dependency property in the SDK reference.

下面的示例演示一个绑定,并设置指定绑定(在前面的绑定示例中未显示出来)的源的 DataContext 属性。The following example shows a binding, and sets the DataContext property that specifies the source of the binding, which was not shown in the earlier binding example. 子对象中的任何后续绑定都无需指定源,它们可以使用父对象 StackPanelDataContext 的继承值。Any subsequent bindings in child objects do not need to specify the source, they can use the inherited value from DataContext in the parent StackPanel object. (或者,子对象可以选择直接在 Binding 中指定自己的 DataContextSource,并且有意不将继承值用于其绑定的数据上下文。)(Alternatively, a child object could instead choose to directly specify its own DataContext or a Source in the Binding, and to deliberately not use the inherited value for data context of its bindings.)

<StackPanel Canvas.Top="50" DataContext="{Binding Source={StaticResource XmlTeamsSource}}">
  <Button Content="{Binding XPath=Team/@TeamName}"/>
</StackPanel>

有关详细信息,请参阅属性值继承For more information, see Property Value Inheritance.

WPF 设计器集成WPF designer integration

如果自定义控件具有实现为依赖属性的属性,则它会收到相应的WPF Designer for Visual Studio支持。A custom control with properties that are implemented as dependency properties will receive appropriate WPF Designer for Visual Studio support. 一个示例就是能够在“属性”窗口中编辑直接依赖属性和附加依赖属性。One example is the ability to edit direct and attached dependency properties with the Properties window. 有关详细信息,请参阅控件创作概述For more information, see Control Authoring Overview.

依赖项属性值优先级Dependency property value precedence

获取依赖属性的值时,获得的值可能是通过参与 WPF 属性系统的其他任一基于属性的输入而在该属性上设置的。When you get the value of a dependency property, you are potentially obtaining a value that was set on that property through any one of the other property-based inputs that participate in the WPF property system. 由于存在依赖属性值优先级,使得属性获取值的方式的各种方案得以按可预测的方式交互。Dependency property value precedence exists so that a variety of scenarios for how properties obtain their values can interact in a predictable way.

请看下面的示例。Consider the following example. 该示例包含适用于所有按钮及其 Background 属性的样式,但也会指定一个具有本地设置的 Background 值的按钮。The example includes a style that applies to all buttons and their Background properties, but then also specifies one button with a locally set Background value.

备注

SDK 文档在讨论依赖属性时有时会使用“本地值”或“本地设置的值”等术语。The SDK documentation uses the terms "local value" or "locally set value" occasionally when discussing dependency properties. 本地设置的值是指在代码中直接为对象实例设置的属性值,或者在 XAML 中设置为元素特性的属性值。A locally set value is a property value that is set directly on an object instance in code, or as an attribute on an element in XAML.

原则上,对于第一个按钮,该属性会设置两次,但是仅应用一个值,即具有最高优先级的值。In principle, for the first button, the property is set twice, but only one value applies: the value with the highest precedence. 本地设置的值具有最高优先级(对于正在运行的动画除外,但是在本示例中没有应用动画),因此,对于第一个按钮的背景将使用本地设置的值,而不使用样式资源库值。A locally set value has the highest precedence (except for a running animation, but no animation applies in this example) and thus the locally set value is used instead of the style setter value for the background on the first button. 第二个按钮没有本地值(而且没有其他比样式资源库优先级更高的值),因此该按钮中的背景来自样式资源库。The second button has no local value (and no other value with higher precedence than a style setter) and thus the background in that button comes from the style setter.

<StackPanel>
  <StackPanel.Resources>
    <Style x:Key="{x:Type Button}" TargetType="{x:Type Button}">
     <Setter Property="Background" Value="Red"/>
    </Style>
  </StackPanel.Resources>
  <Button Background="Green">I am NOT red!</Button>
  <Button>I am styled red</Button>
</StackPanel>

为什么存在依赖属性优先级?Why does dependency property precedence exist?

通常,你不会希望总是应用样式,而且不希望样式遮盖单个元素的哪怕一个本地设置值(否则,通常很难使用样式或元素)。Typically, you would not want styles to always apply and to obscure even a locally set value of an individual element (otherwise, it would be very difficult to use either styles or elements in general). 因此,来自样式的值的操作优先级低于本地设置的值。Therefore, the values that come from styles operate at a lower precedent than a locally set value. 有关依赖属性以及它的有效值可能来自何处的更完整列表,请参阅依赖属性值优先级For a more thorough listing of dependency properties and where a dependency property effective value might come from, see Dependency Property Value Precedence.

备注

在 WPF 元素定义了许多非依赖属性的属性。There are a number of properties defined on WPF elements that are not dependency properties. 一般说来,只有在需要支持至少一个由属性系统启用的方案(数据绑定、样式、动画、默认值支持、继承、附加属性或失效)时,才将属性实现为依赖属性。By and large, properties were implemented as dependency properties only when there were needs to support at least one of the scenarios enabled by the property system: data binding, styling, animation, default value support, inheritance, attached properties, or invalidation.

了解有关依赖属性的详细信息Learning more about dependency properties

  • 附加属性是一种支持 XAML 中的专用语法的属性。An attached property is a type of property that supports a specialized syntax in XAML. 附加属性通常与公共语言运行时(CLR)属性没有1:1 对应关系,并且不一定是依赖属性。An attached property often does not have a 1:1 correspondence with a common language runtime (CLR) property, and is not necessarily a dependency property. 附加属性的典型用途是使子元素可以向其父元素报告属性值,即使父元素和子元素的类成员列表中均没有该属性也是如此。The typical purpose of a attached property is to allow child elements to report property values to a parent element, even if the parent element and child element do not both possess that property as part of the class members listings. 一种主要情况是使子元素能够告知父元素应如何在 UIUI 中呈现它们;有关示例,请参阅 DockLeftOne primary scenario is to enable child elements to inform the parent how they should be presented in UIUI; for an example, see Dock or Left. 有关详细信息,请参阅附加属性概述For details, see Attached Properties Overview.

  • 组件开发人员或应用程序开发人员可能希望创建自己的依赖属性,以便实现数据绑定或样式支持之类的功能,或者实现对失效和值强制的支持。Component developers or application developers may wish to create their own dependency property, in order to enable capabilities such as data binding or styles support, or for invalidation and value coercion support. 有关详细信息,请参阅自定义依赖属性For details, see Custom Dependency Properties.

  • 通常,依赖属性应当被视为公共属性,这些公共属性可以由任何具有实例访问权限的调用方访问,或至少可被这样的调用方发现。Dependency properties should generally be considered to be public properties, accessible or at least discoverable by any caller that has access to an instance. 有关详细信息,请参阅依赖属性的安全性For more information, see Dependency Property Security.

请参阅See also