0

I'm trying to serialize an ink canvas in WPF. So I'm using StrokeCollection.Save to save the strokes to a MemoryStream. But when I try to load the stream into the InkCanvas I get an ArgumentException stating "The length of the ISF data must be greater than zero."
Here's the code sample:

using (MemoryStream ms = new MemoryStream())
{
    inkcanvas.Strokes.Save(ms);
    inkcanvas.Strokes = new System.Windows.Ink.StrokeCollection(ms);
}

What am I missing here?

VMAtm
  • 27,943
  • 17
  • 79
  • 125
SepehrM
  • 1,087
  • 2
  • 20
  • 44

1 Answers1

5

Did you check the Position of the your stream?

I think that after saving the stroke into it it will point to the end of it.
Try to reset the position to the first character, like this:

using (MemoryStream ms = new MemoryStream())
{
    inkcanvas.Strokes.Save(ms);
    ms.Position = 0;
    inkcanvas.Strokes = new System.Windows.Ink.StrokeCollection(ms);
}
VMAtm
  • 27,943
  • 17
  • 79
  • 125