EnumBooleanConvert.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Data;
  6. //----------------------------------------------------------------
  7. //Module Name: $safeprojectname$
  8. //Purpose:
  9. //CopyRight: Muchinfo
  10. //History:
  11. //----------------------------------------------------------------
  12. //DateTime 2016/3/28 9:55:34
  13. //Author
  14. //Description Create
  15. //----------------------------------------------------------------
  16. namespace Muchinfo.MTPClient.Infrastructure.Converters
  17. {
  18. public class EnumBooleanConvert : IValueConverter
  19. {
  20. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  21. {
  22. if (value!=null&&parameter!=null&&(int)value==int.Parse(parameter.ToString()) ) ////值相等的
  23. {
  24. return true;
  25. }
  26. return false;
  27. }
  28. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  29. {
  30. if (value.Equals(true))
  31. {
  32. var result= Enum.Parse(targetType, parameter.ToString());
  33. return result;
  34. }
  35. else
  36. { ////设置值时不进行赋值
  37. var result = Enum.Parse(targetType, "-1");
  38. return result;
  39. }
  40. }
  41. }
  42. }