2

I have a below code

private void inkCanvas1_OnTouchMove(object sender, TouchEventArgs touchEventArgs)
{
    StylusShape EraseShape = (StylusShape)new RectangleStylusShape(20, 20, 0);
    List<Point> enumrator = new List<Point>();
    TouchPoint touchPoint = touchEventArgs.GetTouchPoint(this);

    enumrator.Add(new Point(touchPoint.Position.X, touchPoint.Position.Y));
    inkCanvas1.Strokes.Erase(enumrator, EraseShape);//**reverse operation of this statement**
}

and I want to reverse back erased strokes after performing undo operation.

I have tried below event code. but when i erase multiple strokes then this logic is not performing well.

System.Windows.Ink.StrokeCollection addedStrokes;
System.Windows.Ink.StrokeCollection removedStrokes;
bool undoRedoInProcess = false;

private void Strokes_StrokesChanged(object sender, System.Windows.Ink.StrokeCollectionChangedEventArgs e)
{
    if (undoRedoInProcess)
    {
       addedStrokes = e.Added;
       removedStrokes = e.Removed;
    }       
}


private void Undo()
{
    undoRedoInProcess = true;
    inkCanvas1.Strokes.Remove(removedStrokes);
    inkCanvas1.Strokes.Add(addedStrokes);
    undoRedoInProcess = false;
}
private void Redo()
{
    undoRedoInProcess = true;
    inkCanvas1.Strokes.Add(addedStrokes);
    inkCanvas1.Strokes.Remove(removedStrokes);
    undoRedoInProcess = false;
}
Sandeep Jadhav
  • 815
  • 1
  • 10
  • 27
  • @clemens please check I have updated the code. – Sandeep Jadhav Oct 19 '20 at 11:31
  • 1
    So what exactly isn't working? You haven't shown us anything that is related to a potential undo feature. – Clemens Oct 19 '20 at 11:33
  • I want to reverse back original strokes after erasing strokes from Inkcavnas. inkCanvas1.Strokes.Erase(enumrator, EraseShape);//reverse operation of this statement. – Sandeep Jadhav Oct 19 '20 at 11:41
  • Sure you want that. What have you tried to implement it? When you write "*this logic is not performing well*" there should be something... – Clemens Oct 19 '20 at 11:44
  • I have tried below link also https://stackoverflow.com/a/52911463/7300644 but i'm using palm eraser with touch screen. – Sandeep Jadhav Oct 19 '20 at 11:47
  • 1
    Hi Sandeep, Microsoft don't have undo stroke event for inkcanvas. You can handle the undo redo operations programatically. UWP inkcanvas Undo-Redo operation Link is below: [link](https://edi.wang/post/2017/7/25/uwp-ink-undo-redo) – Maahi Oct 19 '20 at 12:11
  • Thanks maahi but it is in UWP. – Sandeep Jadhav Oct 19 '20 at 12:17

0 Answers0