using System.Windows; using System.Windows.Input; using DI_Electrical.Event; using Newtonsoft.Json.Linq; using Prism.Events; using Prism.Services.Dialogs; using SWS.Commons; using SWS.WPF.Views; using Telerik.Windows.Controls; namespace DI_Electrical.ViewModels { public class MainWindowViewModel : ViewModelBase { #region binding private string _ProjectName; /// ///当前项目 /// public string ProjectName { get { return _ProjectName; } set { _ProjectName = value; OnPropertyChanged(nameof(ProjectName)); } } #endregion /// /// 命令事件 /// public ICommand Command_ShowDialogTest { get; set; } public ICommand Command_ShowDialogSignalManagement { get; set; } private readonly IDialogService _dialogService; private IEventAggregator _eventAggregator; public MainWindowViewModel(IDialogService dialogService , IEventAggregator eventAggregator) { Command_ShowDialogTest = new DelegateCommand(onShowDialogTest); Command_ShowDialogSignalManagement = new DelegateCommand(onShowDialogSignalManagement); _dialogService = dialogService; _eventAggregator= eventAggregator; _eventAggregator.GetEvent().Subscribe(onEnterProjOK, ThreadOption.UIThread, true); } /// /// 选中项目 /// /// private void onEnterProjOK(JToken obj) { ProjectName = GlobalObject.curProject?.ProjectName; } public void onShowDialogTest(object o) { IDialogParameters par = new Prism.Services.Dialogs.DialogParameters(); par.Add(GlobalObject.dialogPar.para1.ToString(), "abc你我他"); _dialogService.ShowDialog(nameof(DialogTest), par, (result) => { var res = result.Parameters.GetValue(GlobalObject.dialogPar.para1.ToString()); if (result.Result == ButtonResult.OK || result.Result == ButtonResult.Yes) { MessageBox.Show("窗体Yes关闭,返回:"+res); } else { MessageBox.Show("窗体NO关闭,返回:" + res); } }); } public void onShowDialogSignalManagement(object o) { IDialogParameters par = new Prism.Services.Dialogs.DialogParameters(); _dialogService.ShowDialog(nameof(DialogSignalManagement), par, (result) => { var res = result.Parameters.GetValue(GlobalObject.dialogPar.para1.ToString()); if (result.Result == ButtonResult.OK || result.Result == ButtonResult.Yes) { } else { } }); } } }