Last active
December 20, 2019 13:44
-
-
Save noutram/a82543e4f25f926aac340362238c72a8 to your computer and use it in GitHub Desktop.
Xamarin Forms Value Converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
... | |
xmlns:local="clr-namespace:NAMESPACE" | |
... | |
<ContentPage.Resources> | |
<ResourceDictionary> | |
<local:IntToBoolConverter x:Key="intToBool" /> | |
</ResourceDictionary> | |
</ContentPage.Resources> | |
... | |
<Button Text="Hello" | |
IsEnabled="{Binding Source={x:Reference entry1}, Path=Text.Length, Converter={StaticResource intToBool}}" /> | |
*/ | |
public class IntToBoolConverter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
return (int)value != 0; | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
return (bool)value ? 1 : 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment