-
Notifications
You must be signed in to change notification settings - Fork 4
Converters
Neil McAlister edited this page Feb 8, 2017
·
1 revision
Xalami includes a XAML Value Converter to make data binding simpler.
Converts a value that is empty or null to a Boolean. Null, empty or falsy values will evaluate to false, and non-null, and truthy values will evaluate to true.
- Null is considered falsy
- Default values for primitive types are considered falsy
- A null or whitespace-only string is considered falsy
- An empty or null
IEnumerableis considered falsy.
Import the Converters namespace, then use it as you would any other value converter:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Xalami.Views"
x:Class="Xalami.Views.MainPage"
xmlns:conv="clr-namespace:Xalami.Converters">
<ContentPage.Resources>
<ResourceDictionary>
<conv:EmptyNullToBoolConverter x:Key="EmptyNullToBoolConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
<ListView ItemsSource="{Binding YourListSource}"
IsVisible="{Binding YourListSource, Converter={StaticResource EmptyNullToBoolConverter}}"/>
</ContentPage>And like any other value converter, you can declare it in your App.xaml if you want to be able to refer to it from any page without declaring it on that page.