title: FlowDocument XamlWriter Save - doesn't preserve tab
body: <p>I am using <code>XamlWriter.Save</code> and <code>XamlReader.Load</code> to serialize and deserialize a FlowDocument to a byte array to store it:</p>
  
  <pre><code>private static byte[] FlowDocumentToByteArray(FlowDocument flowDocument)
  {
      using (var stream = new MemoryStream())
      {
          XamlWriter.Save(flowDocument, stream);
          stream.Position = 0;
          return stream.ToArray();
      }
  }
  
  private static FlowDocument FlowDocumentFromByteArray(byte[] bytes)
  {
      using (var stream = new MemoryStream(bytes))
      {
          return (FlowDocument)XamlReader.Load(stream);
      }
  }
  </code></pre>
  
  <p>However I'm having trouble with whitespace preservation.  The following test fails:</p>
  
  <pre><code>[TestMethod]
  public void FlowDocumentTabsNoBackground()
  {
      var flowDocument = new FlowDocument();
  
      var paragraph = new Paragraph();
      paragraph.Inlines.Add(new Run("\t"));
      paragraph.Inlines.Add(new Run("a"));
      flowDocument.Blocks.Add(paragraph);
  
      byte[] bytes = FlowDocumentToByteArray(flowDocument);
  
      FlowDocument flowDocumentOut = FlowDocumentFromByteArray(bytes);
  
      var textRange = new TextRange(flowDocumentOut.ContentStart, 
          flowDocumentOut.ContentEnd);
      Assert.IsTrue(textRange.Text.StartsWith("\t"));
  }
  </code></pre>
  
  <p>But this test passes:</p>
  
  <pre><code>[TestMethod]
  public void FlowDocumentTabsWithBackground()
  {
      var flowDocument = new FlowDocument();
  
      var paragraph = new Paragraph();
      paragraph.Inlines.Add(new Run("\t"));
      paragraph.Inlines.Add(new Run("a")
          {
              Background = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255))
          }
      );
      flowDocument.Blocks.Add(paragraph);
  
      byte[] bytes = FlowDocumentToByteArray(flowDocument);
  
      FlowDocument flowDocumentOut = FlowDocumentFromByteArray(bytes);
  
      var textRange = new TextRange(flowDocumentOut.ContentStart, 
          flowDocumentOut.ContentEnd);
      Assert.IsTrue(textRange.Text.StartsWith("\t"));
  }
  </code></pre>
  
  <p>Why doesn't the tab make it through the serialze/deserialize cycle and why does adding a background colour to one of the runs in a paragraph help?</p>