Reputation: 31803
Could anyone explain to me why this does not render "VALUE IS DEFAULT"?
<TextBlock Text="{Binding Fail, StringFormat=VALUE IS {0}, FallbackValue=DEFAULT}" />
There is something tricky about this syntax I am missing. Thank you in advance.
Upvotes: 7
Views: 4262
Reputation: 65
I think it could also work using the runs inside the TextBlock :
<TextBlock>
<Run Text="Value is : "/>
<Run Text="{Binding Fail,FallbackValue=Default}"/>
</TextBlock>
?
Upvotes: 1
Reputation: 30810
Binding in WPF does not consider StringFormat while falling back to FallbackValue in case it fails.
You can use what leon suggested or go with PriorityBinding.
--EDIT--
This should work:
<TextBlock DataContext="{Binding Fail, FallbackValue=DEFAULT}" Text="{Binding StringFormat=VALUE IS {0}}" />
Upvotes: 7
Reputation: 2824
The default fallback value is used for priority bindings, if you'd like to display "VALUE IS DEFAULT" for a fallback value, try the following.
<TextBlock Text="{Binding Fail, StringFormat=VALUE IS {0}, FallbackValue='VALUE IS DEFAULT'}" />
Upvotes: 0