Skip to content

Instantly share code, notes, and snippets.

@QiMata
Last active February 25, 2018 02:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save QiMata/b674d8b5a9e8a65910c9 to your computer and use it in GitHub Desktop.
Save QiMata/b674d8b5a9e8a65910c9 to your computer and use it in GitHub Desktop.
Reuse converters by chaining them together with a custom converter.
public class ValueConverterGroup : List<IValueConverter>, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return this.Aggregate(value, (current, converter) => converter.Convert(current, targetType, parameter, culture));
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="someclass">
<ContentPage.Resources>
<ResourceDictionary>
<!-- Converters -->
<ValueConverterGroup x:Key="SelectionBackgroundColorConverter">
<EqualsConverter></EqualsConverter>
<BooleanToColorConverter TrueColor="{StaticResource GreenBackgroundColor}"
FalseColor="{StaticResource GraySeperatorColor}"/>
</ValueConverterGroup>
</ResourceDictionary>
</ContentPage.Resources>
</ContentPage>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment