RobotIdToVisibiltyConverter.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Prism;
  2. using Prism.Ioc;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Data;
  11. using TeamAAS_VP.Core;
  12. using TeamAAS_VP.Enums;
  13. namespace TeamAAS_VP.ValueConverter
  14. {
  15. public class RobotIdToVisibiltyConverter : IValueConverter
  16. {
  17. public bool Inverse { get; set; } = false;
  18. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  19. {
  20. if (value != null && value is Guid id && id != Guid.Empty)
  21. {
  22. var app = (PrismApplicationBase)App.Current;
  23. Management management = app.Container.Resolve<Management>();
  24. var rbt = management.DeviceConfig.Robots.FirstOrDefault(p => p.Id == id);
  25. if (rbt != null)
  26. {
  27. if (rbt.RobotBrand == RobotBrand.XYZ_Platform || rbt.RobotBrand == RobotBrand.XYZU_Platform)
  28. {
  29. return Inverse ? Visibility.Visible : Visibility.Collapsed;
  30. }
  31. return Inverse ? Visibility.Collapsed : Visibility.Visible;
  32. }
  33. else
  34. {
  35. return Visibility.Collapsed;
  36. }
  37. }
  38. else
  39. {
  40. return Visibility.Collapsed;
  41. }
  42. }
  43. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  44. {
  45. return Binding.DoNothing;
  46. }
  47. }
  48. }