using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace FLY.ControlLibrary.Converter
{
    public class Equals2BoolConverter : IValueConverter
    {

        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return false;
            Type tv = value.GetType();

            Type tp = parameter.GetType();
            if (tp.Equals(tv))
            {
                if (value.Equals(parameter))
                    return true;
            }
            return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((bool)value == true)
            {
                return parameter;
            }
            else
            {
                return null;
            }
        }

        #endregion
    }

    /// <summary>
    /// 逻辑反向
    /// </summary>
    public class BoolReverseConverter : IValueConverter
    {

        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool b = (bool)value;
            return !b;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool b = (bool)value;
            return !b;
        }

        #endregion
    }
}
