TargetNullValue property

Binding.TargetNullValue property

Gets or sets the value that is used in the target when the value of the source is null.


property Object^ TargetNullValue { 
   Object^ get();
   void set (Object^ value);

<Binding TargetNullValue="nullValueString" />


XAML Values


A string that can be converted to provide a value for the Binding target in XAML, in cases where the source was null.


An object element instance that can provide a value for the Binding target in XAML, in cases where the source was null.

Property value

Type: System.Object [.NET] | Platform::Object [C++]

The value that is used in the binding target when the value of the source is null.


TargetNullValue might be used for bindings that bind a collection and the source data uses null for missing info only in some of the items. It might also be used for general cases where the data is coming from a database that uses null values as source info to signify something, such as a record that needs more info from the user and isn't complete in the source.

There are two recommended patterns for using TargetNullValue behavior in a Binding:

  • The binding source provides a separate value that is accessed by a different path, which acts as the singleton value that can substitute for any null value coming from a specific data item in the source. For example:
    <Button Content="{Binding Path=NextItem, Mode=OneWay, TargetNullValue={Binding Path=NullValue}}"/>
    Here, NullValue is the path to the substitute value, and is referenced by another Binding.
  • Use resources to provide a value that's specific to your app in cases where the data source provided null and has no suitable property in another path to use as the substitution value. For example,
    <Button Content="{Binding Path=NextItem, Mode=OneWay, TargetNullValue={StaticResource AppStringForNullInAStringABinding}}"/>
    Here, AppStringForNullInAStringABinding is a resource string something like "(value not available)" that lets the user know that there should be data there in most of the data but this particular item didn't have that data from its source. Use resources so that the value can be localized.

FallbackValue is a similar property with similar scenarios. The difference is that a binding uses FallbackValue for cases where the Path and Source doesn't evaluate on the data source at all, or if attempting to set it on the source with a two-way binding throws an exception. It uses TargetNullValue if the Path does evaluate, but the value found there is null.

You can't set the property values of a Binding object after that binding has been attached to a target element and target property. If you attempt this you'll get a run-time exception.

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml::Data [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml::Data [C++]



See also

XAML data binding sample
Data binding in depth



© 2016 Microsoft