|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AreEqualMultiValueConverter.cs" company="Catel development team">
// Copyright (c) 2008 - 2011 Catel development team. All rights reserved.
// </copyright>
// <summary>
// Converts a comparison of 2 bindings to a boolean whether the
// objects are equal or not.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
using System;
using System.Windows.Data;
namespace Catel.Windows.Data.Converters
{
/// <summary>
/// Converts a comparison of 2 bindings to a boolean whether the
/// objects are equal or not.
/// </summary>
#if !SILVERLIGHT
[ValueConversion(typeof(object), typeof(object))]
#endif
public class AreEqualMultiValueConverter : IMultiValueConverter
{
/// <summary>
/// Converts the comparison of 2 values to a boolean.
/// </summary>
/// <param name="values">Values to convert. Only 2 values are supported.</param>
/// <param name="targetType">Not supported.</param>
/// <param name="parameter">Not supported.</param>
/// <param name="culture">Not supported.</param>
/// <returns>True if the values are equal, otherwise false.</returns>
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// Check input
if (values.Length != 2)
{
return false;
}
// Get values
object value1 = values[0];
object value2 = values[1];
// Check if both values are null
if ((value1 == null) && (value2 == null))
{
return true;
}
// Check if one of the values is null
if ((value1 == null) || (value2 == null))
{
return false;
}
// Compare objects
return value1.Equals(value2);
}
/// <summary>
/// Not supported.
/// </summary>
/// <param name="value">Not supported.</param>
/// <param name="targetTypes">Not supported.</param>
/// <param name="parameter">Not supported.</param>
/// <param name="culture">Not supported.</param>
/// <returns>Not supported.</returns>
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
// Not supported (and IMultiValueConverter must return null if no conversion is supported)
return null;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.