PlcIdToNameConverter.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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.Data;
  10. using System.Windows.Forms.Design;
  11. using TeamAAS_VP.Core;
  12. using TeamAAS_VP.Interfaces;
  13. namespace TeamAAS_VP.ValueConverter
  14. {
  15. public class PlcIdToNameConverter : IValueConverter
  16. {
  17. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  18. {
  19. if (value!=null && value is Guid id && id!=Guid.Empty)
  20. {
  21. var app = (PrismApplicationBase)App.Current;
  22. IConfigService configService = app.Container.Resolve<IConfigService>();
  23. var plc = configService.GetAllPlcs().FirstOrDefault(p => p.Id == id);
  24. if (plc!=null)
  25. {
  26. return plc.Name;
  27. }
  28. else
  29. {
  30. return string.Empty;
  31. }
  32. }
  33. else
  34. {
  35. return string.Empty;
  36. }
  37. }
  38. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  39. {
  40. return Binding.DoNothing;
  41. }
  42. }
  43. }