private void AddElement(IElementInitializeModel element) { if (!Elements.ToList().Exists(x => { return(x.Base == element.Base && x.Offset == element.Offset); })) { Elements.Add(element); } }
private void OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { IElementInitializeModel model = e.Row.DataContext as IElementInitializeModel; if (e.EditingElement is TextBox) { TextBox textBox = e.EditingElement as TextBox; if (model is BitElementModel) { if (model.ShowValue.Trim().ToUpper() != "ON" && model.ShowValue.Trim().ToUpper() != "OFF") { e.Cancel = true; LocalizedMessageBox.Show(Properties.Resources.Invalid_Input, LocalizedMessageIcon.Error); } else { if (model.ShowValue.Trim().ToUpper() == "ON") { model.Value = 1; } else { model.Value = 0; } } } else { try { uint tempvalue = ValueConverter.ParseShowValue(textBox.Text, (WordType)Enum.ToObject(typeof(WordType), model.DataType)); model.Value = tempvalue; } catch (Exception ex) { e.Cancel = true; LocalizedMessageBox.Show(Properties.Resources.Invalid_Input, LocalizedMessageIcon.Error); } } } else { ComboBox combox = e.EditingElement as ComboBox; if (model is WordElementModel && model.SelectIndex != combox.SelectedIndex) { WordType oldType = (WordType)Enum.ToObject(typeof(WordType), model.SelectIndex + 1); WordType newType = (WordType)Enum.ToObject(typeof(WordType), combox.SelectedIndex + 1); try { model.ShowValue = ValueConverter.ChangeShowValue(oldType, newType, model.Value); } catch (Exception ex) { e.Cancel = true; LocalizedMessageBox.Show(Properties.Resources.Message_Converter_Error, LocalizedMessageIcon.Error); } } } }