TextLengthToVisibilityConverter.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Data;
  5. namespace Compdfkit_Tools.Common
  6. {
  7. [ValueConversion(typeof(string), typeof(Visibility))]
  8. public class TextLengthToVisibilityConverter: IValueConverter
  9. {
  10. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  11. {
  12. if (value == null)
  13. {
  14. return Visibility.Collapsed;
  15. }
  16. else
  17. {
  18. if (value is string)
  19. {
  20. string checkStr = (string)value;
  21. if(string.IsNullOrEmpty(checkStr)==false)
  22. {
  23. return Visibility.Collapsed;
  24. }
  25. }
  26. return Visibility.Visible;
  27. }
  28. }
  29. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  30. {
  31. return null;
  32. }
  33. }
  34. [ValueConversion(typeof(string), typeof(Visibility))]
  35. internal class InvertTextLengthToVisibilityConverter : IValueConverter
  36. {
  37. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  38. {
  39. if (value == null)
  40. {
  41. return Visibility.Collapsed;
  42. }
  43. else
  44. {
  45. if (value is string)
  46. {
  47. string checkStr = (string)value;
  48. if (string.IsNullOrEmpty(checkStr) == false)
  49. {
  50. return Visibility.Visible;
  51. }
  52. }
  53. return Visibility.Collapsed;
  54. }
  55. }
  56. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  57. {
  58. return null;
  59. }
  60. }
  61. }