簡體   English   中英

如何在列表中存儲InkCanvas的內容

[英]How to store the content of an InkCanvas in a List

我正在對InkCanvas實現撤消/重做功能,因此每次修改InkCanvas的內容時,都需要將其內容保存在列表(而不是文件)中。 我目前將其保存在InMemoryRandomAccessStream但是由於它需要是一個實例,因此無法在列表中使用它。 有沒有一種方法可以存儲多個內容並在必要時進行檢索?

根據撤消/重做功能的要求,可以使用AddStrokeDeleteSelected方法添加或刪除要撤消或重做的筆划。 這是我的代碼,您可以參考。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM