/// <summary> /// 添加仪器 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void NewBtn_ClickAsync(object sender, RoutedEventArgs e) { //创建创建仪器对话框 var dialog3 = new InputDialog3(); dialog3.Model().Label1 = "Instrument Name"; dialog3.Model().Label3 = "Communication Type"; dialog3.Model().ItemsSource = new ObservableCollection <ComboBoxItemModel>(SystemSettings.Comm1); dialog3.Model().Input1 = ""; dialog3.Model().WarningMsg1 = "Input not available!"; dialog3.Model().Input1Validation = ( s => { return(!SystemSettings.InstrumentsList.Any(t => t.Name.ToUpper() == s.ToUpper())); }); Input: var result = await DialogHost.Show(dialog3, "RootDialog", new DialogClosingEventHandler((s, t) => { })); if ((bool)result) { var typeStr = ((ComboBoxItemModel)dialog3.Model().Input3).Name; var type = (CommunicationType)Enum.Parse(typeof(CommunicationType), typeStr); //仪器通讯类型错误则返回重新选择类型 if (type == CommunicationType.None) { await this.MsgBox("Please select the correct communication type."); goto Input; } var instr = new InstrumentModel() { Name = dialog3.Model().Input1, Description = dialog3.Model().Input1, CommnunicationType = type, Config = CommunicationBase.CreateCfg(type), CommReference = CommunicationBase.CreateCommunication(type) }; //添加仪器至全局变量 SystemSettings.InstrumentsList.Add(instr); //选中当前添加的仪器 Instruments.SelectedItem = instr; } }