private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { AttributeTypesDataGridItem item = (AttributeTypesDataGridItem)e.Row.Item; if (item.IsValid()) { e.Row.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0)); } else { e.Row.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0)); } OnAttributeTypesChanged?.Invoke(this); }
private void buttonLoadAttrinuteTypes_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog ofd = new OpenFileDialog() { Filter = SerializationData.FileDialogFilter, Title = SerializationData.LoadAttributeTypesFileDialogTitle }; Nullable <bool> ofdResult = ofd.ShowDialog(); if (ofdResult == true) { XDocument attributeTypesXDocument = XDocument.Load(ofd.FileName); foreach (var attributeTypesXElement in attributeTypesXDocument.Elements()) { if (attributeTypesXElement.Name.ToString().Equals(SerializationData.AttributeTypesNode)) { foreach (var attributeTypeXElement in attributeTypesXElement.Elements()) { if (attributeTypeXElement.Name.ToString().Equals(SerializationData.AttributeTypeNode)) { AttributeTypesDataGridItem item = new AttributeTypesDataGridItem(); foreach (var attributeTypeXAttribute in attributeTypeXElement.Attributes()) { if (attributeTypeXAttribute.Name.ToString().Equals(SerializationData.IsUse)) { item.IsUse = Convert.ToBoolean(attributeTypeXAttribute.Value); } if (attributeTypeXAttribute.Name.ToString().Equals(SerializationData.AttributeTypeName)) { item.Name = attributeTypeXAttribute.Value; } if (attributeTypeXAttribute.Name.ToString().Equals(SerializationData.AttrinuteTypeType)) { switch (attributeTypeXAttribute.Value) { case "Boolean": { item.Type = Types.Boolean; } break; case "Integer": { item.Type = Types.Integer; } break; case "Float": { item.Type = Types.Float; } break; case "String": { item.Type = Types.String; } break; default: { throw new Exception(); } break; } } if (attributeTypeXAttribute.Name.ToString().Equals(SerializationData.AttributeTypeValues)) { item.Values += attributeTypeXAttribute.Value; } } _items.Add(item); if (!item.IsValid()) { //todo сделать получение строки по элементу } } } } } dataGrid.Items.Refresh(); if (OnFileLoaded != null) { OnFileLoaded(sender, "Типы тарибутов загружены из файла " + ofd.FileName + "."); } } } catch (Exception ex) { if (OnErrorOccured != null) { OnErrorOccured(this, ex.Message); } } }