RobotIdToVisibiltyConverter.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. using TeamAAS_VP.Interfaces;
  14. namespace TeamAAS_VP.ValueConverter
  15. {
  16. public class RobotIdToVisibiltyConverter : IValueConverter
  17. {
  18. public bool Inverse { get; set; } = false;
  19. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  20. {
  21. if (value != null && value is Guid id && id != Guid.Empty)
  22. {
  23. var app = (PrismApplicationBase)App.Current;
  24. IConfigService configService = app.Container.Resolve<IConfigService>();
  25. var rbt = configService.GetAllRobots().FirstOrDefault(p => p.Id == id);
  26. if (rbt != null)
  27. {
  28. if (rbt.RobotBrand == RobotBrand.XYZ_Platform || rbt.RobotBrand == RobotBrand.XYZU_Platform)
  29. {
  30. return Inverse ? Visibility.Visible : Visibility.Collapsed;
  31. }
  32. return Inverse ? Visibility.Collapsed : Visibility.Visible;
  33. }
  34. else
  35. {
  36. return Visibility.Collapsed;
  37. }
  38. }
  39. else
  40. {
  41. return Visibility.Collapsed;
  42. }
  43. }
  44. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  45. {
  46. return Binding.DoNothing;
  47. }
  48. }
  49. }