[英]How to store the content of an InkCanvas in a List
我正在对InkCanvas
实现撤消/重做功能,因此每次修改InkCanvas
的内容时,都需要将其内容保存在列表(而不是文件)中。 我目前将其保存在InMemoryRandomAccessStream
但是由于它需要是一个实例,因此无法在列表中使用它。 有没有一种方法可以存储多个内容并在必要时进行检索?
根据撤消/重做功能的要求,可以使用AddStroke
和DeleteSelected
方法添加或删除要撤消或重做的笔划。 这是我的代码,您可以参考。
private List<InkStroke> undoList = new List<InkStroke>();
private void Undo(object sender, RoutedEventArgs e)
{
IReadOnlyList<InkStroke> inkList = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();
if (inkList.Count > 0)
{
InkStroke undoStroke = inkList[inkList.Count - 1];
undoStroke.Selected = true;
undoList.Add(undoStroke.Clone());
inkCanvas.InkPresenter.StrokeContainer.DeleteSelected();
}
}
private void Redo(object sender, RoutedEventArgs e)
{
if (undoList.Count > 0)
{
InkStroke redoStroke = undoList[undoList.Count - 1];
inkCanvas.InkPresenter.StrokeContainer.AddStroke(redoStroke);
undoList.Remove(redoStroke);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.