IncreaseValueToVisibilityConverter.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Data;
  7. using Muchinfo.MTPClient.Data.Helper;
  8. namespace Muchinfo.MTPClient.Infrastructure.Converters
  9. {
  10. /// <summary>
  11. /// 涨跌幅转换为Visibility
  12. /// </summary>
  13. public class IncreaseValueToVisibilityConverter : IValueConverter
  14. {
  15. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  16. {
  17. if (value == null || parameter == null)
  18. {
  19. return Visibility.Collapsed;
  20. }
  21. decimal intValue;
  22. int intParameter;
  23. if (!decimal.TryParse(value.ToString(), out intValue))
  24. {
  25. intValue = 0;
  26. }
  27. if (!int.TryParse(parameter.ToString(), out intParameter))
  28. {
  29. intParameter = 0;
  30. }
  31. if (intValue == 0 || intParameter == 0) return Visibility.Collapsed;
  32. if (intValue > 0)
  33. {
  34. if (intParameter == 1) return Visibility.Visible;
  35. if (intParameter == 2) return Visibility.Collapsed;
  36. }
  37. else
  38. {
  39. if (intParameter == 1) return Visibility.Collapsed;
  40. if (intParameter == 2) return Visibility.Visible;
  41. }
  42. return Visibility.Collapsed;
  43. }
  44. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  45. {
  46. return 0;
  47. }
  48. }
  49. }