Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Missing FallbackValue in Binding

$
0
0

Hello,

I started to rewrite an "Windows Phone" application with Forms.
I have many bindings in my windows phone application that use the FallBackValue property.
Sample :

<TextBlock Text="{Binding MyObject.Text}" Visibility="{Binding MyObject.Text, Converter={StaticResource NotEmptyToVisibilityConverter}, FallbackValue=Collapsed}" />

In Forms, the property doesn't exist and my xaml looks like this :

<Label Text="{Binding MyObject.Text}" IsVisible="{Binding MyObject.Text, Converter={StaticResource NotEmptyToBoolConverter}}" />

The problem is that when my object is null, the binding fails and Forms takes the default value of the bindable property (true for IsVisible).

I have found only a solution with triggers :

<Label Text="{Binding MyObject.Text}" IsVisible="false">
<ContentView.Triggers>
<DataTrigger TargetType="Label"
Binding="{Binding MyObject.Text, Converter={StaticResource NotEmptyToBoolConverter}}" Value="True">
<Setter Property="IsVisible" Value="True" />
</DataTrigger>
</ContentView.Triggers>
</Label>

This solution is really verbose but what do you think of it ? Is there performance problem with this solution ?
And if somebody knows why there is not FallbackValue in Xamarin Binding, it would be interesting. It is not a complicated feature to add.

Thanks,

Olivier


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>