Partager via


x:Null markup extension

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

Specifies null as a value for a property being set through a XAML attribute.

XAML attribute usage

<object property="{x:Null}" .../>

XAML object element usage

<object>
  <object.property>
    <x:Null />
  </object.property>
</object>

Remarks

null is the null reference keyword for C# and C++. The Microsoft Visual Basic keyword for a null reference is Nothing.

The x:Null markup extension has no settable properties.

null is not necessarily the initial unset value for a reference-type dependency property. The initial default value can vary for each dependency property. Many dependency properties will not accept null as a value, either through markup or code, due to their internal implementation. In such cases, setting a XAML attribute value with x:Null can result in a parser exception.

x:Null is a markup extension. Makup extensions in XAML use the "{" and "}" characters as recognized by XAML processor implementations for escaping the handling of attribute values to be other than literals or handler references. Attribute syntax is the most common syntax used with this markup extension. x:Null may also be used in property element syntax.

Some Windows Runtime types are nullable. In cases where a nullable type does not already have null as the default, you could use x:Null to set to the null value in XAML. If using Visual C++ component extensions (C++/CX), nullable types are represented as Platform::IBox<T>. If using Microsoft .NET languages, nullable types are represented as Nullable<T>.

Nullable<T>

IReference<T>