Header and Footer elements are block-container elements, i.e. they can contain Tables and Paragraphs. Each Section contains three Header and three Footer instances.
Headers and Footers are properties of the Section element and each Section can have the following types of Headers and Footers:
- Default: Default header/footer for the Section pages.
- First: Used on the first page of the Section.
- Even: Used on even numbered pages of the Section.
Visualization of headers and footers is additionally affected by the following properties:
RadFlowDocument.HasDifferentEvenOddPageHeadersFooters: If set to true, Even header/footer is used for even document pages. If set to false (which is the default), Even header/footer is not respected.
Section.HasDifferentFirstPageHeaderFooter: If set to true, First header/footer is used for the first page of the section. If set to false (which is the default), First header/footer is not respected.
Section.HeaderTopMargin: Gets or sets the top margin of the header. The value is in device independent pixels (1/96 inch).
Section.FooterBottomMargin: Gets or sets the bottom margin of the footer. The value is in device independent pixels (1/96 inch).
Headers of all HeaderFooterType types can be created using the code snippet in Example 1:
[C#] Example 1: Create a header
RadFlowDocument document = new RadFlowDocument(); document.Sections.AddSection(); document.Sections.First().Headers.Add(); // Creates the default Header. document.Sections.First().Headers.Add(HeaderFooterType.First); document.Sections.First().Headers.Add(HeaderFooterType.Even);
Footers can be created using the code snippet from Example 2:
[C#] Example 2: Create a footer
RadFlowDocument document = new RadFlowDocument(); document.Sections.AddSection(); document.Sections.First().Footers.Add(); // Creates the default Footer. document.Sections.First().Footers.Add(HeaderFooterType.First); document.Sections.First().Footers.Add(HeaderFooterType.Even);
The Parent property of Header and Footer contains reference to the Section from which it is obtained.
You can obtain the Headers and Footers in a Section through the Default, Even and First properties of its Headers or Footers property. For example, if you want to get the default Header element of a Section element, you can use the following line of code:
[C#] Example 3: Get the default header of a section
Header defaultHeader = section.Headers.Default;
Similarly to the Header, the Footer element can be obtained as follows:
[C#] Example 4: Get the default footer of a section
Footer defaultFooter = section.Footers.Default;
If header or footer of particular type is not added, the value of the corresponding property is Null.
Example 5 demonstrates how to add different headers for odd and even pages:
[C#] Example 5: Add headers for even and odd pages
RadFlowDocument document = new RadFlowDocument(); document.Sections.AddSection(); document.HasDifferentEvenOddPageHeadersFooters = true; Header defaultHeader = document.Sections.First().Headers.Add(); Paragraph defaultHeaderParagraph = defaultHeader.Blocks.AddParagraph(); defaultHeaderParagraph.TextAlignment = Alignment.Right; defaultHeaderParagraph.Inlines.AddRun("This is a sample odd page header."); Header evenHeader = document.Sections.First().Headers.Add(HeaderFooterType.Even); Paragraph evenHeaderParagraph = evenHeader.Blocks.AddParagraph(); evenHeaderParagraph.TextAlignment = Alignment.Left; evenHeaderParagraph.Inlines.AddRun("This is a sample even page header.");
When visualizing flow documents, applications may apply additional rules for evaluating the header/footer, which should be presented on a particular page. If header/footer of given type is omitted for a Section, it is inherited from the previous section (also known as "linked to previous"), or – if this is the first section – blank header/footer is used.
For example, if a document with two sections is created and Default, Even and Odd properties are set to headers (footers) only for the first section, the second section is visualized with the same set of headers (footers). If you want to explicitly set blank headers (footers) for a given section, you should explicitly set them to blank headers (footers).
Elements of type Header have a property corresponding to a collection of watermarks - Watermarks. The property provides the ability to add a Watermark to the specific header with the Add() method.
Information on the types of watermarks and their use is available in the Watermark help article.