Added Undo and Redo
This commit is contained in:
@@ -84,7 +84,8 @@ public class MainWindowViewModel : ViewModelBase
|
||||
private void OnCanvasPointerPressed(PointerPressedEventArgs? e)
|
||||
{
|
||||
if (e == null) return;
|
||||
|
||||
if(UndoDrawingPoints.Count > 0) UndoDrawingPoints.Clear();
|
||||
|
||||
IsDrawing = true;
|
||||
DrawingPoints.Add(new DrawingPoints(Brush, BrushThickness));
|
||||
DrawingPoint = DrawingPoints[^1];
|
||||
@@ -111,4 +112,26 @@ public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
IsDrawing = false;
|
||||
}
|
||||
|
||||
public void GlobalKeyUpHandler(KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyModifiers != KeyModifiers.Control) return;
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Z:
|
||||
if (DrawingPoints.Count > 0)
|
||||
{
|
||||
UndoDrawingPoints.Add(DrawingPoints[^1]);
|
||||
DrawingPoints.Remove(DrawingPoints[^1]);
|
||||
}
|
||||
break;
|
||||
case Key.Y:
|
||||
if (UndoDrawingPoints.Count > 0)
|
||||
{
|
||||
DrawingPoints.Add(UndoDrawingPoints[^1]);
|
||||
UndoDrawingPoints.Remove(UndoDrawingPoints[^1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user