StringToVisibleConvert.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 PDF_Office.DataConvert
  10. {
  11. public class StringToVisibleConvert : IValueConverter
  12. {
  13. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  14. {
  15. if (value == null || string.IsNullOrEmpty((string)value))
  16. {
  17. return Visibility.Collapsed;
  18. }
  19. else
  20. {
  21. if (value is string && (value as string).Length > 0)
  22. {
  23. return Visibility.Visible;
  24. }
  25. else
  26. {
  27. return Visibility.Collapsed;
  28. }
  29. }
  30. }
  31. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  32. {
  33. return null;
  34. }
  35. }
  36. public class StringToUnVisibleConvert : IValueConverter
  37. {
  38. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  39. {
  40. if (value == null)
  41. {
  42. return Visibility.Visible;
  43. }
  44. else
  45. {
  46. if (value is string && (value as string).Length > 0)
  47. {
  48. return Visibility.Collapsed;
  49. }
  50. else
  51. {
  52. return Visibility.Visible;
  53. }
  54. }
  55. }
  56. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  57. {
  58. return null;
  59. }
  60. }
  61. }