Code:
MapElement selectedElement = e.Element; selectedElement.Layer.DerenderElement(selectedElement); SqlShapeReader read = selectedElement.Layer.Reader as SqlShapeReader; IEnumerable<Dictionary<string, string>> buffer = read.DataSource as IEnumerable<Dictionary<string, string>>; Dictionary<string, string> buf = buffer.Where(b => b["IDENT"] == selectedElement.Name).Single(); this.IsEnabled = false; ChangeObr changeWin = new ChangeObr(buf); changeWin.btnSave.Click += (s, o) => { string layerName = "layer" + buf["comp_obr"]; SqlShapeReader newReader = xamMap.Layers[layerName].Reader as SqlShapeReader; List<Dictionary<string, string>> source = new List<Dictionary<string, string>>(); source = newReader.DataSource as List<Dictionary<string, string>>; source.Add(buf); newReader.DataSource = source; newReader.ImportAsync(newReader.Layer); xamMap.Layers[layerName].RenderElement(selectedElement); if(changeWin != null) changeWin.Close(); this.IsEnabled = true; xamMap.Layers[layerName].RenderWindow(); }; changeWin.btnCancel.Click+= (s, o) => { this.IsEnabled = true; selectedElement.Layer.RenderElement(selectedElement); }; changeWin.ShowDialog();
Explanation: When I click on a map element I get it's data source (it is Dictionary<string,string> with 4 pairs<Key,Value> - one of them is the sql geometry type) then I send this item to the new window where I change the comp_obr of the Company (which determines the layer this element belongs to) and derender it from the layer. Then if I don't save the new comp_obr I just render this element again. Otherwise if I save the new comp_obr I get the edited item and add it to the source of the new layer and render the layer. But in the way I have written I duplicate the selected element. I understood that by the number of elements of the new and the old layer of the element. The new has increased by 1 element, but the hasn't decreased by 1. My aim is to change the item's comp_obr value and visually to show this change by moving this element to the new layer. Thanks in advance!
The bolded row deletes my old element so I don't have duplicate element:
changeWin.btnSave.Click += (s, o) => {
selectedElement.Layer.Elements.Remove(selectedElement); string layerName = "layer" + buf["comp_obr"];
------------------------------------------------------------------------------------
But I still think there has to be another way for moving elements(not only the visual but and the data) between layers