Freigeben über


x:Null Markup Extension

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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 keyword for a null reference in many managed programming languages. The Visual Basic keyword for a null reference is Nothing.

The x:Null markup extension has no settable properties.

Note that 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 Silverlight 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 targeting Silverlight 3, you cannot use the object element form <x:Null>

See Also

Concepts