using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls.Primitives; using System.Windows.Input; using TProduct.ProcessDrawing.Components; using TProduct.ProcessDrawing.Models; namespace TProduct.ProcessDrawing.ViewModels { /// /// 对应窗口的业务逻辑 /// public class ShowViewModel : ViewModelBase { public ObservableCollection DeviceList { get; set; } = new ObservableCollection(); private DeviceItem4Config currentDevice; public DeviceItem4Config CurrentDevice { get => currentDevice; set => Set(ref currentDevice, value); } private string _saveFailedMessage; public string SaveFailedMessage { get { return _saveFailedMessage; } set { Set(ref _saveFailedMessage, value); } } public RelayCommand CheckFlowCommand { get; set; } public RelayCommand DeviceSelectedCommand { get; set; } public void SetCurrentPipeIndex(int pipeIndex) { if (DeviceList == null) return; foreach(var d in DeviceList) { if (d.IsHavePipeIndex(pipeIndex) && d.UiComponent is ComponentBase) { (d.UiComponent as ComponentBase).IsShowFlowAnimation = 1; } } } public ShowViewModel() { if (!IsInDesignMode) { // 初始化组态组件 InititialDevices(); // DeviceSelectedCommand = new RelayCommand(model2 => { // 记录一个当前选中组件 // Model = DeviceItemModel // 对当前组件进行选中 // 进行属性、点位编辑 if (CurrentDevice != null) CurrentDevice.IsSelected = false; if (model2 != null) { model2.IsSelected = true; } CurrentDevice = model2; }); CheckFlowCommand = new RelayCommand(obj => { var btn = obj as ToggleButton; if (btn.IsChecked == true) { foreach(var p in this.DeviceList) { if(p.UiComponent is ComponentBase) { (p.UiComponent as ComponentBase).StartAnimation(); } } } else { foreach (var p in this.DeviceList) { if (p.UiComponent is ComponentBase) { (p.UiComponent as ComponentBase).StopAnimation(); } } } //(obj as Window).DialogResult = _windowState; }); } } //初始化组态组件 private void InititialDevices() { if(DeviceList == null) { DeviceList = new ObservableCollection(); } List all_DeviceItemModels = null; if (!ProcessDrawingConfigFileHelper.ReadFile(out all_DeviceItemModels)) { return; } foreach (var dim in all_DeviceItemModels) { DeviceList.Add(dim); } } private void BuildDeviceComponet(DeviceItem4Config dim) { dim.UiComponent = DeviceItemHelper.Convert(dim); } } }