ShowStatusViewModel.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Prism.Mvvm;
  2. using System.Linq;
  3. using Prism.Events;
  4. using SHJX.Service.Common.Event;
  5. using System.Collections.Generic;
  6. using SHJX.Service.Model.EventArgs;
  7. using SHJX.Service.Control.Interface;
  8. using System.Collections.ObjectModel;
  9. using SHJX.Service.Common.Constants;
  10. using SHJX.Service.Model.ControlModules;
  11. namespace SHJX.Service.Main.ViewModels
  12. {
  13. public class ShowStatusViewModel : BindableBase
  14. {
  15. #region Properties
  16. public ObservableCollection<StatusControlInfo> StatusControls { get; set; }
  17. //public ShowStatusValueArgs ShowstatusValue { get; set; }
  18. /// <summary>
  19. /// 端口连接状态
  20. /// </summary>
  21. private string _showstatusValue;
  22. public string ShowstatusValue
  23. {
  24. get => _showstatusValue;
  25. set => SetProperty(ref _showstatusValue, value);
  26. }
  27. #endregion
  28. public ShowStatusViewModel(IEventAggregator ea, IMainService service)
  29. {
  30. //ShowstatusValue = new ShowStatusValueArgs();
  31. StatusControls = new ObservableCollection<StatusControlInfo>();
  32. StatusControlInfo control = new()
  33. {
  34. Index = 0,
  35. ControlName = "3232",
  36. TagNameText = "42423",
  37. BackColor = ColorNames.MainColor
  38. };
  39. StatusControls.Add(control);
  40. #region 监听
  41. ea.GetEvent<UpdateStausEvent>().Subscribe((lists) =>
  42. {
  43. string[] strArray = ShowstatusValue?.Split('\r');
  44. if (strArray?.Length >= 9)
  45. {
  46. ShowstatusValue = "";
  47. for (int i = 0; i < 8;i++)
  48. {
  49. ShowstatusValue += strArray[strArray.Length - 9 + i] + "\r";
  50. }
  51. }
  52. ShowstatusValue += lists.CurrentContent + "\r";
  53. });
  54. #endregion
  55. }
  56. #region Event Methods
  57. public void ChangeElement(ShowStatusValueArgs args)
  58. {
  59. // showText = args.CurrentContent;
  60. //StatusControlInfo control = StatusControls.Where(item => item.ControlName.Equals(arg.Name)).FirstOrDefault();
  61. //if (control is null)
  62. //{
  63. // continue;
  64. //}
  65. //StatusControls[control.Index].CurrentTextText = !arg.Enable ? string.IsNullOrWhiteSpace(arg.Current) ? string.Empty : arg.Current.Length < 2 ? arg.Current : arg.Current[1..] : string.Empty;
  66. // StatusControls[control.Index].BackColor = !arg.Enable ? ColorNames.SentColor : ColorNames.MainColor;
  67. //StatusControls[0].ControlName = args.CurrentContent;
  68. // StatusControlsIndex].BackColor = !arg.Enable ? ColorNames.SentColor : ColorNames.MainColor;
  69. }
  70. #endregion
  71. }
  72. }