XAML Section

This article shows how to create and use a Section in a WPF FlowDocument using XAML.
  • 2737

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.

Here is XAML example:

<FlowDocument >

    <Section Background="Red">


            Paragraph 1



            Paragraph 2



            Paragraph 3




C# example:

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Documents;

namespace SDKSample
    public partial class SectionExample : Page
        public SectionExample()

            // 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


© 2020 DotNetHeaven. All rights reserved.