执行inkCanvas1.Strokes.Erase()之后,WPF-InkCanvas撤消操作

时间:2020-10-19 11:18:08

标签: c# wpf multi-touch stroke inkcanvas

我有下面的代码

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**
}

,我想在执行撤消操作后将擦除的笔划向后撤消。

我已经尝试了以下事件代码。但是当我擦除多个笔划时,此逻辑效果不佳。

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;
}

0 个答案:

没有答案