Skip to main content

Section.GetHeaderAsync(HeaderFooterType, Boolean, CancellationToken) Method

Returns a sub-document that is the section’s header.

Namespace: DevExpress.Blazor.RichEdit

Assembly: DevExpress.Blazor.RichEdit.v23.2.dll

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask<SubDocument> GetHeaderAsync(
    HeaderFooterType type = HeaderFooterType.Odd,
    bool createIfNotExist = false,
    CancellationToken cancellationToken = default(CancellationToken)
)

Optional Parameters

Name Type Default Description
type HeaderFooterType Odd

The type of header to be returned.

createIfNotExist Boolean False

true to create a header if it does not exist; false to not create a header.

cancellationToken CancellationToken null

An object that propagates a cancellation notification.

Returns

Type Description
ValueTask<SubDocument>

A structure that stores an awaitable result of an asynchronous operation. The awaitable result is a sub-document object.

Remarks

A main sub-document consists of at least one logical section. Each section can have its own header of the following types: first, primary, odd, and even.

Page header and footer

Call the GetHeaderAsync method to get a sub-document that is the section header. Use the type parameter to specify the type of the header to return. If the section has no header of the specified type, you can set createIfNotExist to true to create the new header.

<DxRichEdit @ref="richEdit" />

@code {
    DxRichEdit richEdit;
    Document documentAPI;
    /* Surround the code that contains an asynchronous operation with a try-catch block to handle
    the OperationCanceledException. This exception is thrown when an asynchronous operation is canceled. */
        try {
            documentAPI = richEdit.DocumentAPI;
            Section firstSection = await documentAPI.Sections.GetAsync(0);
            var header = await firstSection.GetHeaderAsync(HeaderFooterType.Primary, true);
            await header.AddTextAsync("Developer Express Inc.");          
            var hParagraph = await header.Paragraphs.GetAsync(0);
            await hParagraph.ChangePropertiesAsync(properties => {
                properties.Alignment = ParagraphAlignment.Right;
            });
            await firstSection.ChangePropertiesAsync(properties => {
                properties.HeaderOffset = 700;
            });
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}
See Also