Binding.FallbackValue property

Applies to Windows and Windows Phone

Gets or sets the value to use when the binding is unable to return a value.

Syntax


public object FallbackValue { get; set; }


<Binding FallbackValue="fallbackValue" />


<Binding>
  <Binding.FallbackValue>
    fallbackValue
    </Binding.FallbackValue>
</Binding>


XAML Values

fallbackValue

An attribute or object element value of the same type as the target property. This varies with each Binding. See the documentation for the property you're binding to and use that XAML syntax for the XAML in your FallbackValue. That property might support attribute syntax for values, or might only support object element syntax. You can also use another Binding or a StaticResource reference to fill the attribute syntax by using an existing object from a ResourceDictionary.

Property value

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

The value to use when the binding is unable to return a value.

Remarks

Usually you specify FallbackValue for bindings that display strings in UI. For this case the FallbackValue is also a string. You might want to use a resource so that it's easier to localize this string.

If you do specify a literal string for FallbackValue, you must use alternate quotes for the FallbackValue value within the Binding markup extension usage if your string contains spaces, because the Binding markup extension usage for an attribute is already within quotes. For example, <object property="{Binding FallbackValue='A literal string'}" />.

If used within a Binding markup extension usage, the value for FallbackValue can use any implicit string conversions that are already available to XAML, such as treating 0 as a string for a string binding, or converting enum values. For example, <object property="{Binding Path=Visibility, FallbackValue=Collapsed}" /> is valid because the parser can evaluate the string "Collapsed" and return Visibility.Collapsed as the fallback for a Visibility value.

TargetNullValue is a similar property with similar scenarios. The difference is that a binding uses FallbackValue for cases where the Path 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 that's caught by the data binding engine. FallbackValue is also used if the source value is the dependency property sentinel value DependencyProperty.UnsetValue. A binding uses TargetNullValue if the Path and Source do 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

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

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

Metadata

Windows.winmd

See also

Binding
TargetNullValue
XAML data binding sample
Data binding overview

 

 

Show:
© 2014 Microsoft