Back to Devexpress

DxRichEdit.ScrollToPositionAsync(Int32, SubDocument, Int32, CancellationToken) Method

blazor-devexpress-dot-blazor-dot-richedit-dot-dxrichedit-dot-scrolltopositionasync-x28-system-dot-int32-devexpress-dot-blazor-dot-richedit-dot-subdocument-system-dot-int32-system-dot-threading-dot-cancellationtoken-x29.md

latest6.3 KB
Original Source

DxRichEdit.ScrollToPositionAsync(Int32, SubDocument, Int32, CancellationToken) Method

Scrolls the document to the specified position.

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
public ValueTask ScrollToPositionAsync(
    int position,
    SubDocument subDocument = null,
    int pageIndex = 0,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

NameTypeDescription
positionInt32

The target position in the document.

|

Optional Parameters

NameTypeDefaultDescription
subDocumentSubDocumentnull

The target sub-document (header or footer).

| | pageIndex | Int32 | 0 |

The page index.

| | cancellationToken | CancellationToken | null |

An object that propagates a cancellation notification.

|

Returns

TypeDescription
ValueTask

A structure that stores an awaitable result of an asynchronous operation.

|

Remarks

Call the ScrollToPositionAsync method to scroll the view to the specified position in the main sub-document or in headers/footers (using optional parameters). If you need to scroll the document to a specific page, use the ScrollToPageAsync method.

The following sections describe how to use the ScrollToPositionAsync method in different scenarios.

razor
<DxRichEdit @bind-DocumentContent="@documentContent" @ref="richEdit" />
<DxButtonGroup RenderStyle="ButtonRenderStyle.Secondary">
    <Items>
        <DxButtonGroupItem Text="Start position" Click="ScrollToStartPosition" />
        @* ... *@
    </Items>
</DxButtonGroup>

@code {
    DxRichEdit richEdit;
    byte[] documentContent;
    string filePath = "C:\\Users\\Public\\example.docx";

    protected override async Task OnInitializedAsync() {
        documentContent = await File.ReadAllBytesAsync(filePath);
        await base.OnInitializedAsync();
    }

    async Task ScrollToStartPosition() {
        await richEdit.ScrollToPositionAsync(0);
    }
}

Find a Specific String

razor
<DxRichEdit @bind-DocumentContent="@documentContent" @ref="richEdit" />
<DxButtonGroup RenderStyle="ButtonRenderStyle.Secondary">
 <Items>
     <DxButtonGroupItem Text="Text" Click="ScrollToText" />
     @* ... *@
 </Items>
</DxButtonGroup>

@code {
 DxRichEdit richEdit;
 byte[] documentContent;
 string filePath = "C:\\Users\\Public\\example.docx";

 protected override async Task OnInitializedAsync() {
     documentContent = await File.ReadAllBytesAsync(filePath);
     await base.OnInitializedAsync();
 }

 async Task ScrollToText() {
     string searchText = "Beverly"; 
     var intervals = await richEdit.DocumentAPI.FindAllAsync(searchText, true); 
     Interval? interval = intervals.FirstOrDefault(); 
     if(interval != null) 
         await richEdit.ScrollToPositionAsync(interval.Start); 
 }
}

Find a Bookmark by Its Name

razor
<DxRichEdit @bind-DocumentContent="@documentContent" @ref="richEdit" />
<DxButtonGroup RenderStyle="ButtonRenderStyle.Secondary">
    <Items>
        <DxButtonGroupItem Text="Bookmark" Click="ScrollToBookmark" />
        @* ... *@
    </Items>
</DxButtonGroup>

@code {
    DxRichEdit richEdit;
    byte[] documentContent;
    string filePath = "C:\\Users\\Public\\example.docx";

    protected override async Task OnInitializedAsync() {
        documentContent = await File.ReadAllBytesAsync(filePath);
        await base.OnInitializedAsync();
    }

    async Task ScrollToBookmark() {
        string bookmarkName = "Vernon";
        var bookmark = await richEdit.DocumentAPI.Bookmarks.GetAsync(bookmarkName);
        await richEdit.ScrollToPositionAsync(bookmark.Interval.Start); 
    }
}

Scroll to the Third Page Header

razor
<DxRichEdit @bind-DocumentContent="@documentContent" @ref="richEdit" />
<DxButtonGroup RenderStyle="ButtonRenderStyle.Secondary">
 <Items>
     @* ... *@
     <DxButtonGroupItem Text="3rd page header" Click="ScrollToHeader" />
 </Items>
</DxButtonGroup>

@code {
 DxRichEdit richEdit;
 byte[] documentContent;
 string filePath = "C:\\Users\\Public\\example.docx";

 protected override async Task OnInitializedAsync() {
     documentContent = await File.ReadAllBytesAsync(filePath);
     await base.OnInitializedAsync();
 }

 async Task ScrollToHeader() {
     Section section = await richEdit.DocumentAPI.Sections.GetAsync(0);
     SubDocument header = await section.GetHeaderAsync();
     if(header != null)
         await richEdit.ScrollToPositionAsync(0, header, 2);
 }
}
razor
<DxRichEdit @bind-DocumentContent="@documentContent" @ref="richEdit" />
<DxButtonGroup RenderStyle="ButtonRenderStyle.Secondary">
 <Items>
     <DxButtonGroupItem Text="1st page footer" Click="ScrollToFooter" />
     @* ... *@
 </Items>
</DxButtonGroup>

@code {
 DxRichEdit richEdit;
 byte[] documentContent;
 string filePath = "C:\\Users\\Public\\example.docx";

 protected override async Task OnInitializedAsync() {
     documentContent = await File.ReadAllBytesAsync(filePath);
     await base.OnInitializedAsync();
 }

 async Task ScrollToFooter() {
     Section section = await richEdit.DocumentAPI.Sections.GetAsync(0);
     SubDocument footer = await section.GetFooterAsync();
     if(footer != null)
         await richEdit.ScrollToPositionAsync(0, footer);
 }
}

See Also

DxRichEdit Class

DxRichEdit Members

DevExpress.Blazor.RichEdit Namespace