maxp
maxp

Reputation: 25161

`FallbackValue` not evaluated on Binding with empty `Path` in WPF XAML?

On a Page with no DataContext the fallback value is never evaluated, resulting in a blank TextBlock shown.

For example:

<TextBlock DataContext="{x:Null}" Text="{Binding  FallbackValue='HelloWorld'}"></TextBlock>

or

<TextBlock DataContext="{x:Null}" Text="{Binding Path='' FallbackValue='HelloWorld'}"></TextBlock>

Whereas the following Binding, also with a null DataContext *does* show it's FallbackValue.

<TextBlock DataContext="{x:Null}" Text="{Binding NonExistantProperty, FallbackValue='HelloWorld'}"></TextBlock>

Upvotes: 2

Views: 1938

Answers (1)

nicolas2008
nicolas2008

Reputation: 1052

You should you use TargetNullValue instead of FallbackValue in your case.
FallbackValue is used when something is wrong with the Binding path or value.
In you case there is nothing wrong: null value can be bound to the TextBlock.Text.

Upvotes: 6

Related Questions