PlcIdToNameConverter.cs 1.2 KB

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