| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using Prism.Mvvm;
- using System.Linq;
- using Prism.Events;
- using SHJX.Service.Common.Event;
- using System.Collections.Generic;
- using SHJX.Service.Model.EventArgs;
- using SHJX.Service.Control.Interface;
- using System.Collections.ObjectModel;
- using SHJX.Service.Common.Constants;
- using SHJX.Service.Model.ControlModules;
- namespace SHJX.Service.Main.ViewModels
- {
- public class OpLiquidPosViewModel : BindableBase
- {
- #region Properties
- public ObservableCollection<CenterControlInfo> CenterControls { get; set; }
- #endregion
- public OpLiquidPosViewModel(IEventAggregator ea, IMainService service)
- {
- var positions = service.OtherPositions;
- CenterControls = new ObservableCollection<CenterControlInfo>();
- for (int i = 0; i < positions.Count; i++)
- {
- CenterControlInfo control = new()
- {
- Index = i,
- ControlName = positions[i].Name,
- TagNameText = positions[i].TagText,
- BackColor = ColorNames.MainColor
- };
- CenterControls.Add(control);
- }
- #region 监听
- ea.GetEvent<UpdateElementEvent>().Subscribe(ChangeElement);
- #endregion
- }
- #region Event Methods
- public void ChangeElement(List<ElementArgs> args)
- {
- foreach (ElementArgs arg in args)
- {
- CenterControlInfo control = CenterControls.Where(item => item.ControlName.Equals(arg.Name)).FirstOrDefault();
- if (control is null)
- {
- continue;
- }
- CenterControls[control.Index].CenterText = !arg.Enable ? string.IsNullOrWhiteSpace(arg.Current) ? string.Empty : arg.Current.Length < 2 ? arg.Current : arg.Current[1..] : string.Empty;
- CenterControls[control.Index].BackColor = !arg.Enable ? ColorNames.SentColor : ColorNames.MainColor;
- }
- }
- #endregion
- }
- }
|