DependencyProperty.UnsetValue Field


指定由 WPFWPF 属性系统使用的静态值而非 null,以指示属性存在,但其值未经属性系统设置。Specifies a static value that is used by the WPFWPF property system rather than null to indicate that the property exists, but does not have its value set by the property system.

public: static initonly System::Object ^ UnsetValue;
public static readonly object UnsetValue;
 staticval mutable UnsetValue : obj
Public Shared ReadOnly UnsetValue As Object 

Field Value



UnsetValue 是一个 sentinel 值,用于 WPFWPF 属性系统无法确定请求的 DependencyProperty 值的方案。UnsetValue is a sentinel value that is used for scenarios where the WPFWPF property system is unable to determine a requested DependencyProperty value. 使用 UnsetValue 而不是 null,因为 null 可以是有效的属性值,也可以是有效的(并经常使用的) DefaultValueUnsetValue is used rather than null, because null could be a valid property value, as well as a valid (and frequently used) DefaultValue.

永远不会从 DependencyObject.GetValue中返回 UnsetValueUnsetValue is never returned out of DependencyObject.GetValue. DependencyObject 实例上的依赖属性调用 DependencyObject.GetValue 时,以下情况之一适用:When you call DependencyObject.GetValue on a dependency property on a DependencyObject instance, one of the following applies:

  • 依赖属性具有在元数据中建立的默认值,并且返回该值。A dependency property has a default value established in metadata and that value is returned. 此值可能来自 DefaultMetadataThis value might come from DefaultMetadata.

  • 其他一些值由属性系统建立,并且默认值不再相关。Some other value was established by the property system, and the default value is no longer relevant. 有关详细信息,请参阅依赖属性值优先级For details, see Dependency Property Value Precedence.

明确禁止设置 UnsetValue DefaultValueSetting a DefaultValue of UnsetValue is specifically disallowed.

如果未本地设置请求的属性,DependencyObject.ReadLocalValue 将返回 UnsetValueDependencyObject.ReadLocalValue returns UnsetValue when the requested property has not been locally set.

UnsetValue 在用作 CoerceValueCallback的返回值时具有特殊意义。UnsetValue has a special meaning when used as the return value of a CoerceValueCallback. 有关详细信息,请参阅依赖属性回调和验证For details, see Dependency Property Callbacks and Validation.

如果要绑定到数据库,请注意,UnsetValueValue不等效,Value 与 true null 不等效。If you are binding to a database, note that UnsetValue is not equivalent to Value, in a similar way to how Value is not equivalent to a true null.

Applies to