Nice MultiValueConverter

If you have a MultiBinding and you want to get true when every binding evaluates to the same value, then this is four you, little pollo:

 public class AllEqualConverter : IMultiValueConverter
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
            if (!values.Any())
                return true;

            var first = values.First();

            var allAreTheSame = values.All(other => Equals(first, other));
            return allAreTheSame;

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
            throw new NotSupportedException("This is only mean to support conversions in One Way");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s