using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Data; namespace FLY.Thick.Base.UI.Converter { public class EnumToVisibilityConverter : IValueConverter where TEnum : struct { #region IValueConverter 成员 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { TEnum type = (TEnum)value; bool enable = false; if (Enum.GetName(typeof(TEnum), type) == (parameter as string)) enable = true; string p = null; if (parameter != null) p = parameter as string; if (enable) return System.Windows.Visibility.Visible; else return System.Windows.Visibility.Hidden; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } public class Equals2VisibleConverter : IValueConverter { #region IValueConverter 成员 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Type tv = value.GetType(); Type tp = parameter.GetType(); if (tp.Equals(tv)) { if (value.Equals(parameter)) return System.Windows.Visibility.Visible; } return System.Windows.Visibility.Hidden; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } public class Equals2VisibleConverter_Collapsed : IValueConverter { #region IValueConverter 成员 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Type tv = value.GetType(); Type tp = parameter.GetType(); if (tp.Equals(tv)) { if (value.Equals(parameter)) return System.Windows.Visibility.Visible; } return System.Windows.Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } public class Equals2CollapsedConverter : IValueConverter { #region IValueConverter 成员 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Type tv = value.GetType(); Type tp = parameter.GetType(); if (tp.Equals(tv)) { if (value.Equals(parameter)) return System.Windows.Visibility.Collapsed; } return System.Windows.Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } public class Equals2HiddenConverter : IValueConverter { #region IValueConverter 成员 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Type tv = value.GetType(); Type tp = parameter.GetType(); if (tp.Equals(tv)) { if (value.Equals(parameter)) return System.Windows.Visibility.Hidden; } return System.Windows.Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } public class Equals2BoolConverter : IValueConverter { #region IValueConverter 成员 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { 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 } }