Bug 22720

Summary: Add support for TargetNullValue and FallbackValue in XAML bindings
Product: Forms Reporter: Jérémie Di Prizio <jeremie.diprizio>
Component: FormsAssignee: Bugzilla <bugzilla>
Status: RESOLVED ANSWERED    
Severity: enhancement CC: arpitj, bpanjevic, dstefanov, eric.maupin, jas, jemeryh646, luca.masini, nitescua, oansquer, sahou, sas, seth.rosetter, tony, zabrucewayne
Priority: Normal    
Version: 1.2.2   
Target Milestone: ---   
Hardware: All   
OS: All   
Tags: Is this bug a regression?: ---
Last known good build:

Description Jérémie Di Prizio 2014-09-06 12:15:11 UTC
At the moment, using either TargetNullValue or FallbackValue in a XAML binding raises a TargetInvocationException which leads me to believe that neither of these properties are implemented (seems to be confirmed by your API reference).

Would be great if they were implemented as setting those fallback/replacement values in the view model code is a bit noisy.

For reference here are the MSDN pages of those properties:

TargetNullValue: http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.targetnullvalue(v=vs.110).aspx
FallbackValue: http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.fallbackvalue(v=vs.110).aspx
Comment 1 Arpit Jha 2014-09-08 05:53:21 UTC
I have checked this issue with some XAML binding and unable to reproduce it.

Could you please provide us sample project/Steps to reproduce ,build and Environment info also ,So that i can able to check at our end.
Comment 2 Bojan Panjevic 2014-12-11 00:08:31 UTC
I'm also able to confirm the issue. Here is a part of the XAML

 <DataTemplate x:Key="ProfileItemTemplate">
        <ViewCell>
          <ViewCell.View>
            <StackLayout Orientation="Vertical" Padding="10,0,10,0" HorizontalOptions="Fill">
              <Label Text="{Binding Description}" Font="Large" HorizontalOptions="Fill"/>
              <StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand">
                <Entry Text="{Binding Text}" VerticalOptions="Center" WidthRequest="350"
                       IsVisible="{Binding IsTextRequired}" />
                <Switch VerticalOptions="Center"
                  IsVisible="{Binding IsTextRequired, Converter={StaticResource InvertBooleanConverter }}"
                  IsToggled="{Binding IsChecked, TargetNullValue=False}}"/>
              </StackLayout>
            </StackLayout>
          </ViewCell.View>
        </ViewCell>
      </DataTemplate>
Comment 3 Olivier Ansquer 2016-01-22 20:15:09 UTC
These properties are important and it should not be difficult to add. Why so long? Do you have a simple alternative solution?
Comment 4 Jason Smith [MSFT] 2016-03-16 12:34:42 UTC
The request got set to NEEDS INFO somehow (looks like the triager got confused) and the feature request never made it to the dev team. Im digging through the backlog now trying to find everything and just ran across this.

Its now added to the feature board.
Comment 5 Sascha Schwegelbauer 2016-10-02 13:20:06 UTC
Status: RESOLVED FEATURE ?!

-> It's not present in current 2.3.1.114
Comment 6 Jason Smith [MSFT] 2017-02-14 19:40:19 UTC
This is not on our current roadmap.
Comment 7 JeremyH 2017-02-14 20:19:35 UTC
So after almost 3 years, for such a basic feature:

1. "triager got confused, Its now added to the feature board."

2. "This is not on our current roadmap"

I honestly haven't experienced any library vendor worse than Xamarin.
Comment 8 Olivier Ansquer 2017-02-15 08:12:57 UTC
+1 for JeremyH's answer. This type of response is incomprehensible on such a simple evolution.
Comment 9 zabrucewayne 2017-05-23 14:32:13 UTC
This would be very useful, please consider adding to the backlog.
Comment 10 dstefanov 2017-11-19 03:35:08 UTC
Fallback binding value is indeed very important feature! 
Simple example is: I have IsVisible attribute bind to the BindingContext.IsBuzy where Binding property is set to a ViewModel with property IsBuzy.
By default IsBuzy is false and the control would be hidden. However, what happens when the ViewModel is not set to the BindingContext and the BindingContext is null? The binding fails to find object and property to bind to. When this happens the DefaultValue of property IsVisible is used - True. Now the control would be visible when there is no binding context and by default we want it to be hidden.
If there was a Fallback value we could set it to False for such scenarios where we can't control the BindingContext.
Notice that this is very distinct scenario and is also very common since this is the recommended way to use the BindingContext.