Solved! Go to Solution.
public static ESRI.ArcGIS.Client.Graphic CloneGraphic(this ESRI.ArcGIS.Client.Graphic g) { ESRI.ArcGIS.Client.Graphic newGraphic = new ESRI.ArcGIS.Client.Graphic() { MapTip = g.MapTip, Symbol = g.Symbol, TimeExtent = g.TimeExtent, Selected = g.Selected, Geometry = g.Geometry.CloneGeometry() }; g.Attributes.CopyTo(newGraphic.Attributes); return newGraphic; } public static Geometry CloneGeometry(this Geometry g) { Geometry newGeometry = null; if (g is ESRI.ArcGIS.Client.Geometry.Envelope) { var env = g as Envelope; newGeometry = new Envelope() { SpatialReference = env.SpatialReference, XMax = env.XMax, YMax = env.YMax, XMin = env.XMin, YMin = env.YMin, }; } else if (g is ESRI.ArcGIS.Client.Geometry.MapPoint) { var point = g as MapPoint; newGeometry = new MapPoint(point.X, point.Y, point.SpatialReference); } else if (g is ESRI.ArcGIS.Client.Geometry.MultiPoint) { var mpoint = g as MultiPoint; var pc = new PointCollection(); foreach (var p in mpoint.Points) pc.Add(new MapPoint(p.X, p.Y, p.SpatialReference)); newGeometry = new MultiPoint(pc, mpoint.SpatialReference); } else if (g is ESRI.ArcGIS.Client.Geometry.Polygon) { var poly = g as Polygon; var newPoly = new Polygon() { SpatialReference = poly.SpatialReference }; foreach (var ring in poly.Rings) { var pc = new PointCollection(); foreach (var p in ring) pc.Add(new MapPoint(p.X, p.Y, p.SpatialReference)); newPoly.Rings.Add(pc); } newGeometry = newPoly; } else if (g is ESRI.ArcGIS.Client.Geometry.Polyline) { var line = g as Polyline; var newline = new Polyline() { SpatialReference = line.SpatialReference }; foreach (var path in line.Paths) { var pc = new PointCollection(); foreach (var p in path) pc.Add(new MapPoint(p.X, p.Y, p.SpatialReference)); newline.Paths.Add(pc); } newGeometry = newline; } return newGeometry; } public class EditSnapshot { public EditSnapshot() { Graphics = new List<Graphic>(); } public EditSnapshot(Graphic g) : this() { Graphics.Add(g); } public EditSnapshot(IEnumerable<Graphic> graphics) : this() { Graphics.AddRange(graphics); } public List<Graphic> Graphics { get; set; } } //Here is the actual code that we use. Pretty simple. internal protected Stack<EditSnapshot> Snapshots { get; set; } private void EditGeometry_GeometryEdit(object sender, EditGeometry.GeometryEditEventArgs e) { if (e.Action == EditGeometry.Action.EditCompleted) Snapshots.Push(new EditSnapshot(_editLayer.Graphics.Select(x => x.CloneGraphic()))); }
public static ESRI.ArcGIS.Client.Graphic CloneGraphic(this ESRI.ArcGIS.Client.Graphic g) { ESRI.ArcGIS.Client.Graphic newGraphic = new ESRI.ArcGIS.Client.Graphic() { MapTip = g.MapTip, Symbol = g.Symbol, TimeExtent = g.TimeExtent, Selected = g.Selected, Geometry = g.Geometry.CloneGeometry() }; g.Attributes.CopyTo(newGraphic.Attributes); return newGraphic; } public static Geometry CloneGeometry(this Geometry g) { Geometry newGeometry = null; if (g is ESRI.ArcGIS.Client.Geometry.Envelope) { var env = g as Envelope; newGeometry = new Envelope() { SpatialReference = env.SpatialReference, XMax = env.XMax, YMax = env.YMax, XMin = env.XMin, YMin = env.YMin, }; } else if (g is ESRI.ArcGIS.Client.Geometry.MapPoint) { var point = g as MapPoint; newGeometry = new MapPoint(point.X, point.Y, point.SpatialReference); } else if (g is ESRI.ArcGIS.Client.Geometry.MultiPoint) { var mpoint = g as MultiPoint; var pc = new PointCollection(); foreach (var p in mpoint.Points) pc.Add(new MapPoint(p.X, p.Y, p.SpatialReference)); newGeometry = new MultiPoint(pc, mpoint.SpatialReference); } else if (g is ESRI.ArcGIS.Client.Geometry.Polygon) { var poly = g as Polygon; var newPoly = new Polygon() { SpatialReference = poly.SpatialReference }; foreach (var ring in poly.Rings) { var pc = new PointCollection(); foreach (var p in ring) pc.Add(new MapPoint(p.X, p.Y, p.SpatialReference)); newPoly.Rings.Add(pc); } newGeometry = newPoly; } else if (g is ESRI.ArcGIS.Client.Geometry.Polyline) { var line = g as Polyline; var newline = new Polyline() { SpatialReference = line.SpatialReference }; foreach (var path in line.Paths) { var pc = new PointCollection(); foreach (var p in path) pc.Add(new MapPoint(p.X, p.Y, p.SpatialReference)); newline.Paths.Add(pc); } newGeometry = newline; } return newGeometry; } public class EditSnapshot { public EditSnapshot() { Graphics = new List<Graphic>(); } public EditSnapshot(Graphic g) : this() { Graphics.Add(g); } public EditSnapshot(IEnumerable<Graphic> graphics) : this() { Graphics.AddRange(graphics); } public List<Graphic> Graphics { get; set; } } //Here is the actual code that we use. Pretty simple. internal protected Stack<EditSnapshot> Snapshots { get; set; } private void EditGeometry_GeometryEdit(object sender, EditGeometry.GeometryEditEventArgs e) { if (e.Action == EditGeometry.Action.EditCompleted) Snapshots.Push(new EditSnapshot(_editLayer.Graphics.Select(x => x.CloneGraphic()))); }