JobDocumentSetDescriptionConverter.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Data;
  5. using InABox.Core;
  6. namespace PRSDesktop
  7. {
  8. public class JobDocumentSetDescriptionConverter : IValueConverter
  9. {
  10. public object Convert(object value, Type t, object parameter, CultureInfo culture)
  11. {
  12. try
  13. {
  14. if ((value == null) || String.Equals(value,""))
  15. return "";
  16. var description = Serialization.Deserialize<JobDocumentSetDescriptionBlock>(value.ToString());
  17. if (String.Equals(parameter, "ID"))
  18. return description?.ID ?? Guid.Empty;
  19. if (String.Equals(parameter, "Code"))
  20. return description?.Code ?? "";
  21. if (String.Equals(parameter, "Description"))
  22. return description?.Description ?? "";
  23. if (String.Equals(parameter, "Tags"))
  24. return String.Join(", ",description?.Tags ?? new String[] { });
  25. return parameter?.ToString() ?? "";
  26. }
  27. catch (Exception e)
  28. {
  29. return e.Message;
  30. }
  31. }
  32. public object ConvertBack(object value, Type t, object parameter, CultureInfo culture)
  33. {
  34. return value.Equals(false) ? DependencyProperty.UnsetValue : parameter;
  35. }
  36. }
  37. }