public void SyncStrokeEx(Dictionary<InkStroke,double> strokes, InkStrokeContainer containner, double currentCanvasWidth,bool forcrRefresh = false) { lock(locker) { if(strokes.Count > containner.GetStrokes().Count) { foreach (var item in strokes) { bool exist = false; foreach (var itemInner in containner.GetStrokes()) { InkStroke strokeCopy = itemInner.Clone(); strokeCopy.PointTransform = System.Numerics.Matrix3x2.CreateScale(1f); if (InkHelper.SameInkStroke(item.Key, strokeCopy)) { exist = true; break; } } if (!exist) { foreach(var itemMp in StrokeMapping) { if(InkHelper.SameInkStroke(item.Key,itemMp.Key) && item.Value == itemMp.Value) { StrokeMapping.Remove(itemMp.Key); break; } } } } } else if(strokes.Count < containner.GetStrokes().Count) { InkStroke stroke = containner.GetStrokes()[containner.GetStrokes().Count - 1].Clone(); StrokeMapping.Add(stroke.Clone(),currentCanvasWidth); } else { if(strokes.Count == StrokeMapping.Count && !forcrRefresh) { return; } } strokes.Clear(); containner.Clear(); foreach(var item in StrokeMapping) { InkStroke stroke = item.Key.Clone(); strokes.Add(stroke.Clone(), item.Value); stroke.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / item.Value)); containner.AddStroke(stroke.Clone()); } //if(read) //{ // strokes.Clear(); // foreach(var item in StrokeMapping) // { // strokes.Add(item.Key.Clone(),item.Value); // } //} //else //{ // StrokeMapping.Clear(); // foreach(var item in strokes) // { // StrokeMapping.Add(item.Key.Clone(),item.Value); // } //} } }
public void SyncStroke(InkStrokeContainer containner,double currentCanvasWidth,bool syncAll = true, InkStroke stroke = null) { lock(locker) { try { if (syncAll) { Strokes.Clear(); foreach (var item in containner.GetStrokes()) { InkStroke strokeClone = item.Clone(); strokeClone.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / originalCanvasWidth)); Strokes.Add(strokeClone); } } else { if (null != stroke) { InkStroke strokeClone = stroke.Clone(); strokeClone.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / originalCanvasWidth)); Strokes.Add(strokeClone); } else { containner.Clear(); foreach (var item in Strokes) { InkStroke strokeClone = item.Clone(); strokeClone.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / originalCanvasWidth)); containner.AddStroke(strokeClone); } } } } catch(Exception e) { #if DEBUG System.Diagnostics.Debug.WriteLine(e.Message); #endif } } }