| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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<PlcPoint> _Points = new ObservableCollection<PlcPoint>();
- /// <summary>
- /// 点位集合
- /// </summary>
- public ObservableCollection<PlcPoint> 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()
- {
- }
- /// <summary>
- /// 确认按钮
- /// </summary>
- /// <returns></returns>
- bool CanExecuteConfirmCommand()
- {
- return true;
- }
- void ExecuteConfirmCommand()
- {
- IDialogParameters parameters = new DialogParameters();
- parameters.Add("Points", Points.ToArray());
- RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
- }
- /// <summary>
- /// 取消按钮
- /// </summary>
- void ExecuteCancelCommand()
- {
- IDialogParameters parameters = new DialogParameters();
- RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
- }
- /// <summary>
- /// 清除所有补偿值
- /// </summary>
- 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<IDialogResult> RequestClose;
- public bool CanCloseDialog()
- {
- return true;
- }
- public void OnDialogClosed()
- {
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
- Title = parameters.GetValue<string>("Title");
- var pts = parameters.GetValue<PlcPoint[]>("Points");
- if (pts != null)
- {
- Points = new ObservableCollection<PlcPoint>(pts);
- }
- }
- }
- }
|