Skip to main content
All docs
V25.2
  • 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

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

    Parameters

    Name Type Description
    position Int32

    The target position in the document.

    Optional Parameters

    Name Type Default Description
    subDocument SubDocument null

    The target sub-document (header or footer).

    pageIndex Int32 0

    The page index.

    cancellationToken CancellationToken null

    An object that propagates a cancellation notification.

    Returns

    Type Description
    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.

    Rich Text Editor - Scroll To Positions

    <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

    <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

    <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

    <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);
     }
    }
    
    <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