using System; using System.Collections.ObjectModel; using System.Windows; using Prism.Ioc; using Prism.Services.Dialogs; using Telerik.Windows.Controls; using DialogParameters = Prism.Services.Dialogs.DialogParameters; namespace DI_Electrical.ViewModels { public class DialogSignalSelectViewModel : DialogBase, IDialogAware { public DialogSignalSelectViewModel(IContainerProvider container) { title = "信号选择框"; } public event Action RequestClose; public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } private ObservableCollection _listSignal; /// /// 单位列表 /// public ObservableCollection listSignal { get { return _listSignal; } set { _listSignal = value; RaisePropertyChanged(nameof(listSignal)); } } private Signal _SelectedSignal; /// /// 选中的单位 /// public Signal SelectedSignal { get { return _SelectedSignal; } set { _SelectedSignal = value; RaisePropertyChanged(nameof(SelectedSignal)); } } public string Title => "信号选择框"; public void OnDialogOpened(IDialogParameters parameters) { var signals = parameters.GetValue>(GlobalObject.dialogPar.para1.ToString()); listSignal = new ObservableCollection(); foreach (var item in signals) { if (item.type.Equals("信号")) { listSignal.Add(new Signal() { SignalId = item.Wire_Group_ID, SignalName = item.Group_Name }); } } } public override void ExecuteOKCommandAsync(object para) { if (SelectedSignal == null) { MessageBox.Show("请选择一个信号!"); return; } IDialogParameters res = new DialogParameters(); res.Add(GlobalObject.dialogPar.para1.ToString(), SelectedSignal); DialogResult result = new DialogResult(ButtonResult.Yes, res); RequestClose.Invoke(result); } public override void ExecuteCloseCommand(object parameter) { IDialogParameters res = new DialogParameters(); DialogResult result = new DialogResult(ButtonResult.No, res); RequestClose.Invoke(result); this.Dispose(); } } public class Signal : ViewModelBase { private string _SignalId; /// /// Id /// public string SignalId { get { return _SignalId; } set { _SignalId = value; RaisePropertyChanged(nameof(SignalId)); } } private string _SignalName; /// /// 信号 /// public string SignalName { get { return _SignalName; } set { _SignalName = value; RaisePropertyChanged(nameof(SignalName)); } } } }