private void SaveCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { Layer layerToSave = CollectionViewSource.GetDefaultView(Layers).CurrentItem as Layer; if (layerToSave.FileName != "") { saveFileDialog.FileName = Path.GetFileNameWithoutExtension(layerToSave.FileName); saveFileDialog.InitialDirectory = layerToSave.FileName; } if (saveFileDialog.ShowDialog() == true) { string name = saveFileDialog.FileName; try { mapCanvas.CommitAll(); List <Feature> features = new List <Feature>(); foreach (ShapefileShape item in layerToSave.Shapes) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); foreach (ShapefileAttributeEntry items in item.Attributes) { dictionary.Add(items.FieldDescriptor.Name, items.Value); } features.Add(new Feature(item.Geometry, new AttributesTable(dictionary))); } ShapefileDataWriter writer = new ShapefileDataWriter(name, GeometryFactory.Default) { Header = layerToSave.Header }; writer.Write(features); } catch (Exception ex) { Console.WriteLine(ex); } } }