public RowEditorWindow(ImportStagingService service, int rowId, List <ImportFieldMapping> mappings, DataRowView row) { InitializeComponent(); this.Service = service; this.RowID = rowId; this.Row = row; this.Mappings = mappings; int rowIndex = 0; foreach (ImportFieldMapping mapping in mappings) { gridFields.RowDefinitions.Add(CreateRowDefinition()); var lbl = new Label(); lbl.SetValue(Grid.RowProperty, rowIndex); lbl.Content = mapping.SourceColumn; gridFields.Children.Add(lbl); var txt = new Extensibility.TextBox(); txt.SetValue(Grid.ColumnProperty, 1); txt.SetValue(Grid.RowProperty, rowIndex); txt.Height = 23; var objValue = row[mapping.SourceColumn]; var strValue = (objValue == null ? "" : objValue.ToString()); var value = new FieldValue(mapping.TargetColumn, strValue); var binding = new Binding("Value"); binding.Source = value; binding.ValidatesOnDataErrors = true; txt.SetBinding(TextBox.TextProperty, binding); // txt.Text = strValue; var fieldMapping = mapping; // need to keep a copy of this mapping so its captured in the closure txt.TextChanged += new TextChangedEventHandler((source, e) => { var textbox = source as TextBox; if (textbox.Text != strValue) { _changeMap[fieldMapping.SourceColumn] = textbox.Text; } else { if (_changeMap.ContainsKey(fieldMapping.SourceColumn)) { _changeMap.Remove(fieldMapping.SourceColumn); } } }); gridFields.Children.Add(txt); rowIndex++; } }
public RowEditorWindow(ImportStagingService service, int rowId, List<ImportFieldMapping> mappings, DataRowView row) { InitializeComponent(); this.Service = service; this.RowID = rowId; this.Row = row; this.Mappings = mappings; int rowIndex = 0; foreach (ImportFieldMapping mapping in mappings) { gridFields.RowDefinitions.Add(CreateRowDefinition()); var lbl = new Label(); lbl.SetValue(Grid.RowProperty, rowIndex); lbl.Content = mapping.SourceColumn; gridFields.Children.Add(lbl); var txt = new Extensibility.TextBox(); txt.SetValue(Grid.ColumnProperty, 1); txt.SetValue(Grid.RowProperty, rowIndex); txt.Height = 23; var objValue = row[mapping.SourceColumn]; var strValue = (objValue == null ? "" : objValue.ToString()); var value = new FieldValue(mapping.TargetColumn, strValue); var binding = new Binding("Value"); binding.Source = value; binding.ValidatesOnDataErrors = true; txt.SetBinding(TextBox.TextProperty, binding); // txt.Text = strValue; var fieldMapping = mapping; // need to keep a copy of this mapping so its captured in the closure txt.TextChanged += new TextChangedEventHandler((source, e) => { var textbox = source as TextBox; if (textbox.Text != strValue) { _changeMap[fieldMapping.SourceColumn] = textbox.Text; } else { if (_changeMap.ContainsKey(fieldMapping.SourceColumn)) { _changeMap.Remove(fieldMapping.SourceColumn); } } }); gridFields.Children.Add(txt); rowIndex++; } }