Share via


How to: Save the Contents of a FlowDocumentPageViewer as a XAML File

This example demonstrates how to save the contents of a FlowDocumentPageViewer (represented by the Document property) as a XAML file.

Example

The following example defines an empty, named FlowDocumentPageViewer that will be manipulated by the code example below.

<FlowDocumentPageViewer
  Name="flowDocPageViewer" 
  MinZoom="50" MaxZoom="1000"
  Zoom="120" ZoomIncrement="5"
  />

To save the contents of the FlowDocumentPageViewer to a file, open or create the file stream and use the Save method provided by the XamlWriter class to write the FlowDocument to the file stream.

The following example performs these steps.

void SaveFlowDocumentPageViewerWithXAMLFile(string fileName)
{
    // Open or create the output file.
    FileStream xamlFile = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
    // Save the contents of the FlowDocumentReader to the file stream that was just opened.
    XamlWriter.Save(flowDocPageViewer.Document, xamlFile);

    xamlFile.Close();
}

See Also

Tasks

How to: Load a XAML File into a FlowDocumentPageViewer