This article shows how to create and use a Section in a WPF FlowDocument using XAML.
Section is used only to contain other Block-derived elements. It does not apply any default formatting to the elements it contains. However, any property values set on a Section applies to its child elements. A section also enables you to programmatically iterate through its child collection.
Section is used in a similar manner to the <DIV> tag in HTML.
In the example below, three paragraphs are defined under one Section . The section has a Background property value of Red, therefore the background color of the paragraphs is also red.
public partial class SectionExample : Page
// Create three paragraphs
Paragraph myParagraph1 = new Paragraph(new Run("Paragraph 1"));
Paragraph myParagraph2 = new Paragraph(new Run("Paragraph 2"));
Paragraph myParagraph3 = new Paragraph(new Run("Paragraph 3"));
// Create a Section and add the three paragraphs to it.
Section mySection = new Section();
mySection.Background = Brushes.Red;
// Create a FlowDocument and add the section to it.
FlowDocument myFlowDocument = new FlowDocument();
this.Content = myFlowDocument;
Ask Your Question
Got a programming related question? You may want to post your question here