Do inkcanvasa w wpfie chce dodać operacje cofnij i wróc. Prawie działa, jednak jak zrobie cofnij coś narysuje to potem mogę przywrócic to co cofnąłem przed narysowaniem, a tak nie powinno być.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PluginInterfaceNamespace;
namespace PluginApp
{
public partial class MainWindow : Window
{
System.Windows.Ink.StrokeCollection addedStrokes;
System.Windows.Ink.StrokeCollection removedStrokes;
public MainWindow()
{
InitializeComponent();
InkCanvas.DefaultDrawingAttributes.Color = Colors.Black;
InkCanvas.Strokes.StrokesChanged += Strokes_StrokesChanged;
addedStrokes = new System.Windows.Ink.StrokeCollection();
removedStrokes = new System.Windows.Ink.StrokeCollection();
addMenuItems();
}
private void Strokes_StrokesChanged(object sender, System.Windows.Ink.StrokeCollectionChangedEventArgs e)
{
/*if (handle)
{
_added = e.Added;
_removed = e.Removed;
}*/
if (e.Added != null)
{
addedStrokes.Add(e.Added);
removedStrokes.Clear();
}
}
private void Undo_Click(object sender, RoutedEventArgs e)
{
if (addedStrokes.Count != 0)
{
removedStrokes.Add(addedStrokes.ElementAt(addedStrokes.Count - 1));
addedStrokes.RemoveAt(addedStrokes.Count - 1);
}
InkCanvas.Strokes = addedStrokes;
}
private void Redo_Click(object sender, RoutedEventArgs e)
{
if (removedStrokes.Count != 0)
{
addedStrokes.Add(removedStrokes.ElementAt(removedStrokes.Count - 1));
removedStrokes.RemoveAt(removedStrokes.Count - 1);
}
InkCanvas.Strokes = addedStrokes;
}
}
}