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

更新:2007 年 11 月

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

示例

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

<FlowDocumentScrollViewer
  Name="flowDocScrollViewer" 
  HorizontalScrollBarVisibility="Auto" 
  VerticalScrollBarVisibility="Auto" 
  IsSelectionEnabled="True" 
  IsToolBarVisible="True" 
  MinZoom="50" MaxZoom="1000"
  Zoom="120" ZoomIncrement="5"
/>

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

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

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

    xamlFile.Close();
}

请参见

任务

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