RobotConverter.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Data;
  9. using TeamAAS_VP.Core;
  10. using TeamAAS_VP.Models;
  11. namespace TeamAAS_VP.ValueConverter
  12. {
  13. public class RobotConverter : IMultiValueConverter
  14. {
  15. public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
  16. {
  17. try
  18. {
  19. if (value != null && value.Length==2)
  20. {
  21. var lst = (ObservableCollection<RobotInfo>)value[1];
  22. var robotinfo = lst.FirstOrDefault(r => r.Id == (Guid)value[0]);
  23. if (robotinfo != null)
  24. {
  25. return robotinfo.RobotName;
  26. }
  27. else
  28. {
  29. return null;
  30. }
  31. }
  32. else
  33. {
  34. return null;
  35. }
  36. }
  37. catch (Exception)
  38. {
  39. return null;
  40. }
  41. }
  42. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  43. {
  44. return null;
  45. }
  46. }
  47. }