IntToBooleanConvert.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //Copyright (c) 2015, 北京探索者软件公司
  3. //All rights reserved.
  4. //文件名称: IntToBooleanConvert.cs
  5. //文件描述: 根据数字转换布尔类型,前台绑定raido,附加参数使用
  6. //创 建 者: xls
  7. //创建日期: 2016-7-26
  8. //版 本 号:1.0.0.0
  9. ////////////////////////////////////////////////////////////////////////////////
  10. using System;
  11. using System.Globalization;
  12. using System.Windows.Data;
  13. namespace FWindSoft.Wpf
  14. {
  15. /// <summary>
  16. /// 当不想定义枚举是,使用整型值代替
  17. /// </summary>
  18. public class IntToBooleanConvert : IValueConverter
  19. {
  20. public static IntToBooleanConvert Instance = new IntToBooleanConvert();
  21. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  22. {
  23. object returnValue = false;
  24. if (parameter != null)
  25. {
  26. Object paramValue = parameter.ToString();
  27. returnValue = paramValue.Equals(value.ToString());
  28. }
  29. return returnValue;
  30. }
  31. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  32. {
  33. return System.Convert.ToInt32(parameter);
  34. }
  35. }
  36. }