private void SyncGeometriesWithShapes() { if (_context?.Factory == null || Shapes == null) { return; } if (_lineStrokeStyle == null) { //create the default line stroke style _lineStrokeStyle = new StrokeStyle(_d2dFactory, new StrokeStyleProperties { LineJoin = LineJoin.Round, StartCap = CapStyle.Round, EndCap = CapStyle.Round }); } foreach (var shape in Shapes) { if (_createdGeometries.ContainsKey(shape.GeometryHash)) { continue; } //vector not created, make it here and store for later var geometry = CreateGeometry(shape); if (geometry != null) { if (!_createdGeometries.ContainsKey(geometry.GeometryHash)) { _createdGeometries.Add(geometry.GeometryHash, geometry); } } } //get list of geometries that are no longer in the Shapes collection, and delete them foreach (var geoHash in _createdGeometries.Keys.ToList()) { if (Shapes.All(s => s.GeometryHash != geoHash)) { _createdGeometries[geoHash].Dispose(); _createdGeometries.Remove(geoHash); } } }