方法 : FlowDocumentScrollViewer のコンテンツを XAML ファイルとして保存する

更新 : 2007 年 11 月

この例では、Document プロパティで表されている FlowDocumentScrollViewer のコンテンツを XAML ファイルとして保存する方法を示します。

使用例

次の例では、下のコード例によって操作される FlowDocumentScrollViewer という名前の空の要素を定義します。

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

FlowDocumentScrollViewer のコンテンツをファイルに保存するには、ファイル ストリームを開くか、または作成し、XamlWriter クラスによって提供される Save メソッドを使用して 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 に読み込む