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

更新:2007 年 11 月

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

示例

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

<FlowDocumentReader
  Name="flowDocRdr" 
  IsFindEnabled="True"  
  IsPrintEnabled="True"
  MinZoom="50" MaxZoom="1000"
  Zoom="120" ZoomIncrement="5"
/>

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

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

void SaveFlowDocumentReaderWithXAMLFile(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(flowDocRdr.Document, xamlFile);

    xamlFile.Close();
}

有关允许用户将 FlowDocumentReader 的内容另存为 XAML 文件的功能示例,请参见 FlowDocumentReader 加载/保存 XAML 示例

请参见

任务

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