Search code examples
uwpwin-universal-appinkcanvasfilesavepicker

Is this possible to save the inkstroke with list or array?


I'm wondering that how to save the inkstrokes with array or list and etc ways. Because I want to make inkcanvas's page with index variable.

So that user can move the page freely using the index.

For example, I want to save the all inkstrokes drawn so far (not image file), as soon as I click the next page button.

But now I can't find how to save the inkstrokes and open the saved inkstrokes

I want to save the file name and location without Filesavepicker, to keep the file name and location fixed. is this possible?


Solution

  • I'm really wondering that how to save the inkstrokes with array or list and etc ways.

    You could get the InkStroke read only list by InkStrokeContainer.GetStrokes method and save this collection by the way you want. For example:

    IReadOnlyList<InkStroke> strokes = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();
    

    More details please reference Store and retrieve Windows Ink stroke data.

    If your purpose is for loading, you could consider to save strokes to a file, or selected all the strokes and then copy to clipboard for paste. For example:

    private void btnreadd_Click(object sender, RoutedEventArgs e)
    {
        if (inkCanvas.InkPresenter.StrokeContainer.CanPasteFromClipboard())
        {
            inkCanvas.InkPresenter.StrokeContainer.PasteFromClipboard(new Windows.Foundation.Point(50, 50));
        } 
    }
    
    
    private void btncollect_Click(object sender, RoutedEventArgs e)
    {  
        IReadOnlyList<InkStroke> strokes = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();  
        foreach (var stroke in strokes)
        { 
            stroke.Selected = true;
        }
        inkCanvas.InkPresenter.StrokeContainer.CopySelectedToClipboard();
    }