This repository has been archived by the owner on Aug 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
IntegerToBooleanConverter
Mark Smith edited this page Aug 29, 2016
·
1 revision
The IntegerToBooleanConverter
value converter takes a System.Int32
input and turns it into a boolean based on the value of the integer and the setting of three properties.
This value converter can also be created inline with the associated binding as it implements IMarkupExtension
. This is convenient if you are only using one of them in your page/app. However, if you need to reuse the converter, make sure to put it into your resources so that only a single copy is instantiated.
-
ZeroOrNull
: the boolean value to return if the Integer is zero, null, or invalid. Defaults tofalse
. -
Positive
: the boolean value to return if the Integer is > 0. Defaults totrue
. - 'Negative
: the boolean value to return if the Integer is < 0. Defaults to
false`.
In this XAML example, the Label won't be displayed if the ListView
has items.
<Page xmlns:cvt="clr-namespace:XamarinUniversity.Converters;assembly=XamU.Infrastructure">
<Page.Resources>
<ResourceDictionary>
<cvt:IntegerToBooleanConverter x:Key="CountToVisibility" ZeroOrNull="true" Positive="false" />
</ResourceDictionary>
<Page.Resources>
<ListView x:Name="favorites" ... />
<Label Text="No Favorites"
IsVisible="{Binding Count,
Source={x:Reference favorites},
Converter={StaticResource CountToVisibility}}" />