尝试在InkCanvas
上创建自定义撤消和重做。然而,经过一些压力测试(添加大量笔画,撤消和重做很多次),应用程序崩溃:
System.ExecutionEngineException未处理。的HResult = -2146233082
在我的AddToRedoList
方法的foreach循环上。任何人都有任何想法如何捕获和修复异常?
private void AddToRedoList(InkStroke addStroke) {
var addInkPoint = addStroke.GetInkPoints();
var addInkPointList = new List<InkPoint>();
foreach (var point in addInkPoint) {
addInkPointList.Add(new InkPoint(point.Position, point.Pressure));
}
redoCustomStrokeList.Add(new CustomStroke() {
InkPoints = addInkPointList,
DrawingAttributes = addStroke.DrawingAttributes
});
}
private void UndoOnClick(object sender, RoutedEventArgs e) {
var allStrokes = InkImage.InkPresenter.StrokeContainer.GetStrokes();
var undoStroke = allStrokes[allStrokes.Count - 1];
AddToRedoList(undoStroke);
allStrokes[allStrokes.Count - 1].Selected = true;
InkImage.InkPresenter.StrokeContainer.DeleteSelected();
}
private void RedoOnClick(object sender, RoutedEventArgs e) {
var lastRedoInkPoints = redoCustomStrokeList[redoCustomStrokeList.Count-1];
InkImage.InkPresenter.StrokeContainer.AddStroke(CreateStroke(lastRedoInkPoints));
redoCustomStrokeList.Remove(lastRedoInkPoints);
}
}