如何:将 FlowDocumentPageViewer 的内容另存为 XAML 文件

更新:2007 年 11 月

下面的示例演示如何将 FlowDocumentPageViewer(由 Document 属性表示)的内容另存为 XAML 文件。

示例

下面的示例定义一个空的命名 FlowDocumentPageViewer,它将由下面的代码示例操作。

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

若要将 FlowDocumentPageViewer 的内容保存到一个文件,请打开或创建相应的文件流,然后使用 XamlWriter 类提供的 Save 方法将 FlowDocument 写入该文件流中。

下面的示例将执行这些步骤。

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();
}

请参见

任务

如何:将 XAML 文件加载到 FlowDocumentPageViewer 中