using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using TeamAAS_VP.Interfaces; using TeamAAS_VP.Models; using TeamAAS_VP.Models.PLC; using TeamAAS_VP.Resources.Languages; using TeamAAS_VP.Views.Setting; namespace TeamAAS_VP.ViewModels.Product { public class PlcPointOffserParamsViewModel : BindableBase, IDialogAware { #region 属性 private ObservableCollection _Points = new ObservableCollection(); /// /// 点位集合 /// public ObservableCollection Points { get { return _Points; } set { SetProperty(ref _Points, value); } } #endregion #region 命令 private DelegateCommand _ConfirmCommand; public DelegateCommand ConfirmCommand => _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand, CanExecuteConfirmCommand)); private DelegateCommand _CancelCommand; public DelegateCommand CancelCommand => _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand)); private DelegateCommand _ClearAllOffsetCommand; public DelegateCommand ClearAllOffsetCommand => _ClearAllOffsetCommand ?? (_ClearAllOffsetCommand = new DelegateCommand(ExecuteClearAllOffsetCommand)); #endregion public PlcPointOffserParamsViewModel() { } /// /// 确认按钮 /// /// bool CanExecuteConfirmCommand() { return true; } void ExecuteConfirmCommand() { IDialogParameters parameters = new DialogParameters(); parameters.Add("Points", Points.ToArray()); RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters)); } /// /// 取消按钮 /// void ExecuteCancelCommand() { IDialogParameters parameters = new DialogParameters(); RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters)); } /// /// 清除所有补偿值 /// void ExecuteClearAllOffsetCommand() { foreach (var point in Points) { point.X_Offset = 0; point.Y_Offset = 0; point.Z_Start_Offset = 0; point.Z_Stop_Offset = 0; point.U_Offset = 0; point.R_Offset = 0; } } private string _Title; public string Title { get { return _Title; } set { SetProperty(ref _Title, value); } } public event Action RequestClose; public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { Title = parameters.GetValue("Title"); var pts = parameters.GetValue("Points"); if (pts != null) { Points = new ObservableCollection(pts); } } } }