NullExtension Class


实现 XAML 标记扩展以返回 null 对象,你可使用此对象在 XAML 中将值显式设置为 null。Implements a XAML markup extension in order to return a null object, which you can use to explicitly set values to null in XAML.

public ref class NullExtension : System::Windows::Markup::MarkupExtension
public class NullExtension : System.Windows.Markup.MarkupExtension
type NullExtension = class
    inherit MarkupExtension
Public Class NullExtension
Inherits MarkupExtension


在 XAML 中,null 和空字符串通常不等效。In XAML, null and empty string are generally not equivalent. 使用 {x:Null} 扩展用法,以便设置将基础属性设置为 null的属性。You use the {x:Null} extension usage in order to set an attribute that sets the underlying property to null. 有关设置 null 值如何与 XAML 中的方案相关的详细信息,请参阅X:Null 标记扩展For more information on how setting null values is relevant for scenarios in XAML, see x:Null Markup Extension.

此类是一个标记扩展实现。This class is a markup extension implementation. 标记扩展类主要用于为 XAML 处理器解释特定扩展的方式提供基础结构支持。Markup extension classes exist mainly to provide infrastructure support for how XAML processors interpret a particular extension. 标记扩展实现类公开的成员通常不应从代码中调用。The members that markup extension implementation classes expose are not typically intended to be called from your code. 此标记扩展类支持 .NET XAML 服务的X:Null 标记扩展用法。This markup extension class supports the x:Null Markup Extension usage for .NET XAML Services.

在以前版本的 .NET Framework 中,此类(以及 x:Null 标记扩展 XAML 行为支持以及相关的 xmlns 映射)存在于 WPF 特定的程序集 PresentationFramework 中。In previous versions of the .NET Framework, this class (and the x:Null markup extension XAML behavior support as well as the relevant xmlns mapping) existed in the WPF-specific assembly PresentationFramework. .NET Framework 4.NET Framework 4中,NullExtension 在 system.exception 程序集中。In .NET Framework 4.NET Framework 4, NullExtension is in the System.Xaml assembly. 这使得使用引用 .NET XAML 服务的框架的应用程序可以使用 x:Null 使用情况。This makes the x:Null usage available to applications using frameworks that reference .NET XAML Services. 只要目标 .NET Framework 4.NET Framework 4,就不需要 PresentationFramework 作为引用的程序集。You do not need PresentationFramework as a referenced assembly so long as you are targeting .NET Framework 4.NET Framework 4. 有关详细信息,请参阅 Types Migrated from WPF to System.XamlFor more information, see Types Migrated from WPF to System.Xaml.

System.exception 程序集使用 XmlnsDefinitionAttribute 将程序集中的所有类型映射到 XAML 语言的 XAML 命名空间(。The System.Xaml assembly uses XmlnsDefinitionAttribute to map all types in the assembly to the XAML namespace for the XAML language ( 通常,在根元素映射中声明 的前缀,并使用前缀 xTypically you declare a prefix for in a root element mapping and use the prefix x.

WPF 用法说明WPF Usage Notes

对于 WPF 依赖项属性,将依赖项属性值设置为 null时,不一定要将属性设置为其默认值,即使它是引用属性也是如此。For WPF dependency properties, when you set a dependency property value to null, you are not necessarily setting the property to its default value, even if it is a reference property. 依赖项属性的默认值取决于其依赖项属性的注册。The default value of a dependency property depends on its dependency property registration. 无设置值不一定 null;请参阅 UnsetValueAn unset value is not necessarily null either; see UnsetValue. 有关详细信息,请参阅 ClearValue依赖属性概述For more information, see ClearValue or Dependency Properties Overview.



初始化 NullExtension 类的新实例。Initializes a new instance of the NullExtension class.



确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)

提供 null 以用作此标记扩展的输出值。Provides null to use as a value as the output of this markup extension.


返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also