EnumVisibilityConvert.cs 1.5 KB

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