Using XamlFormatProvider
XamlFormatProvider makes it easy to import and export RadDocument to/from XAML format. This is the native format of RadRichTextBox and Using it guarantees that anything in the document will be preserved exactly the same as it is in the control.
To use XamlFormatProvider, you should add a reference to:
- Telerik.Windows.Documents.FormatProviders.Xaml.dll
Import
In order to import a XAML document, you can use the overloads of the Import() method.
Example 1 shows how to use XamlFormatProvider to import XAML document from a file.
Example 1: Import XAML document from a file
XamlFormatProvider xamlformatProvider = new XamlFormatProvider();
using (FileStream inputStream = new FileStream("XamlDocument.xaml",FileMode.Open))
{
this.radRichTextBox.Document = xamlformatProvider.Import(inputStream);
}
Export
In order to export a document to XAML, you need to use the Export() method of XamlFormatProvider.
Example 2 shows how to use XamlFormatProvider to export RadDocument to a file.
Example 3: Export document to a file
XamlFormatProvider provider = new XamlFormatProvider();
using (FileStream output = new FileStream("XamlDocument.xaml",FileMode.OpenOrCreate))
{
RadDocument document = this.radRichTextBox.Document;
provider.Export(document, output);
}