Headers and Footers
RadRichTextBox supports Headers and Footers in its document when in Paged layout mode.
Note that Headers and Footers are not persisted when exporting with HtmlFormatProvider. You can read more about this here.
The topic contains the following sections:
Header Footer Types
The Headers and Footers are properties of a Section and each section in the document can have the following types of Headers and Footers:
First: Used only on the first page of the section.
Even: Used on all even numbered pages in the section.
Default: Used on all pages of the section, where First or Even are not applicable or not specified.
Customizing Headers and Footers
Example 1 demonstrates how you can create a Header.
Example 1: Create Header
Header header = new Header() { Body = radDocument, IsLinkedToPrevious = false }; //radDocument represents the content of a Header,
//typically contains a few paragraphs
When it comes to using a Header created in this manner, this depends on the state of the document - if it has been measured or not.
- In a non-measured document, which you are building in code-behind, you can set the Default page Header of a section as illustrated in Example 2.
Example 2: Set Header of a Section
section.Headers.Default = header;
-
In a measured document (a document that has been previewed in the editor), you can change the Default page header of the first section like shown in Example 3.
Example 3: Update a Header in Measured Document
this.radRichTextBox.UpdateHeader(this.radRichTextBox.Document.Sections.First, HeaderFooterType.Default, header);
All header/footer types - Default, First and Even are set identically. The only thing you should add when you set the First or Even Header/Footer of the document, is to set the property of the section that notifies the document to use different Header/Footer than the default one using one of the properties illustrated in Example 4.
Example 4: Set Different Even/Odd Header
this.radRichTextBox.Document.Sections.First.HasDifferentFirstPageHeaderFooter = true;
//or
this.radRichTextBox.Document.HasDifferentEvenAndOddHeadersFooters = true;
Setting the Footers can be done in the same way. Here is the respective code for footers:
-
Creating a Footer:
Example 5: Create Footer
Footer footer = new Footer() { Body = radDocument, IsLinkedToPrevious = false }; //radDocument is an instance of RadDocument, representing the content of the footer.
-
Setting the Footer to be used in a particular section:
-
In a non-measured document:
Example 6: Set Footer of a Section
section.Footers.Default = footer;
-
In a measured document:
Example 7: Update a Footer in Measured Document
this.radRichTextBox.UpdateFooter(this.radRichTextBox.Document.Sections.First, HeaderFooterType.Default, footer);
-
As for setting different footers for the first page or the even page, this is done by passing the respective parameter to the UpdateFooter() method - HeaderFooterType.First or HeaderFooterType.Even and setting the corresponding property of the document/editor.
Example 8: Set Different Even/Odd Footer
this.radRichTextBox.Document.Sections.First.HasDifferentFirstPageHeaderFooter = true;
//or
this.radRichTextBox.Document.HasDifferentEvenAndOddHeadersFooters = true;
Disabling Headers and Footers
Headers and footers are only present in Paged layout mode, so the easiest way to remove them is to change the layout mode. In case you wish to show documents in paged mode and still disable headers and footers, you can do so by removing the UI layer responsible for their visualization - HeaderFooterLayer.
The concept of UI layers and their usage are explained in this article.
Example 9: Disable Headers and Footers
class CustomUILayerBuilder : UILayersBuilder
{
protected override void BuildUILayersOverride(IUILayerContainer uiLayerContainer)
{
base.BuildUILayersOverride(uiLayerContainer);
uiLayerContainer.UILayers.Remove(DefaultUILayers.HeaderFooterLayer);
}
}