|
|
|
Questions and Answers for Controls FlowDocumentReader.
|
70. Controls FlowDocumentReader
|
| 70.1 How can
I load an XAML file into a FlowDocumentReader?
|
| 70.2 How can
I save the contents of a FlowDocumentReader as an XAML file ?
|
70.1 How can I load an XAML file into a FlowDocumentReader?
|
|
This example demonstrates how to parse an XAML file that contains a FlowDocument
and display the loaded file in a FlowDocumentReader.
|
[XAML]
<FlowDocumentReader
Name="flowDocRdr"
IsFindEnabled="True"
IsPrintEnabled="True"
MinZoom="50" MaxZoom="1000"
Zoom="120" ZoomIncrement="5"
/>
|
|
And write the following FlowDocument to the file stream :
|
[C#]
void LoadFlowDocumentReaderWithXAMLFile(string fileName)
{
// Open the file that contains the FlowDocument...
FileStream xamlFile = new FileStream(fileName, FileMode.Open,
FileAccess.Read);
// and parse the file with the XamlReader.Load method.
FlowDocument content = XamlReader.Load(xamlFile) as
FlowDocument;
// Finally, set the Document property to the FlowDocument
object that was
// parsed from the input file.
flowDocRdr.Document = content;
xamlFile.Close();
}
|
70.2 How can I save the contents of a FlowDocumentReader as an XAML file ?
|
|
This example demonstrates how to save the contents of a FlowDocumentReader
(represented by the "Document" property) as an XAML file.
|
[XAML]
<FlowDocumentReader
Name="flowDocRdr"
IsFindEnabled="True"
IsPrintEnabled="True"
MinZoom="50" MaxZoom="1000"
Zoom="120" ZoomIncrement="5"
/>
|
|
To save the contents of the FlowDocumentReader 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.
|
[C#]
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();
}
|
|