TextLengthToVisibilityConverter.cs 2.0 KB

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