Edit this page

Style Sheets

Style sheets provide an easy way to change the look of documents without altering their content. They extend the support for predefined styles by allowing the saving and loading of custom style sheets – a set of styles to be used throughout the document. What is particularly convenient about them is that you can change the colors and sizes used for headings, TOC entries, etc. just by changing the style sheet.

Instances of the Stylesheet class contain StyleDefinitions and ListStyles. The class also exposes the ApplyStylesheetToDocument and ExtractStylesheetFromDocument methods used respectively for applying and extracting a style sheet.

Below you can see the result when the style sheet of a document is changed

Rad Rich Text Box Features Style Sheets 01

Rad Rich Text Box Features Style Sheets 02

Exporting and Importing Style sheets

XamlFormatProvider has been extended to import and export style sheets to back up this functionality.

Here is an example of how to load a style sheet from a file using the LoadStylesheet method of XamlFormatProvider:

OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Xaml Files|.xaml";
if (ofd.ShowDialog() == true)
{
    using (var stream = ofd.File.OpenRead())
    {
        Stylesheet stylesheet = XamlFormatProvider.LoadStylesheet(stream);
        stylesheet.ApplyStylesheetToDocument(this.editor.Document);
    }
}
Dim ofd As New OpenFileDialog()
ofd.Filter = "Xaml Files|.xaml"
If ofd.ShowDialog() = True Then
    Using stream = ofd.File.OpenRead()
Dim stylesheet As Stylesheet = XamlFormatProvider.LoadStylesheet(stream)
        stylesheet.ApplyStylesheetToDocument(Me.editor.Document)
    End Using
End If

This is how you can save a style sheet with the SaveStyleSheet method of XamlFormatProvider:

SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Xaml Files|.xaml";
if (sfd.ShowDialog() == true)
{
    using (var stream = sfd.OpenFile())
    {
        Stylesheet stylesheet = new Stylesheet();
        stylesheet.ExtractStylesheetFromDocument(this.editor.Document);
        XamlFormatProvider.SaveStylesheet(stylesheet, stream);
    }
}
Dim sfd As New SaveFileDialog()
sfd.Filter = "Xaml Files|.xaml"
If sfd.ShowDialog() = True Then
    Using stream = sfd.OpenFile()
Dim stylesheet As New Stylesheet()
        stylesheet.ExtractStylesheetFromDocument(Me.editor.Document)
        XamlFormatProvider.SaveStylesheet(stylesheet, stream)
    End Using
End If