Search results

Center the dialog based on the current scroll position

14 Apr 2021 / 1 minute to read

The dialog is always centered based on the target container. If the target is not specified, then the dialog will be rendered based on its body and centered in the position of the current viewpoint.

In the following sample, the model dialog is centered based on its current scroll position of the page.

Copied to clipboard
@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Buttons

<SfButton @onclick="@OpenDialog">Open Modal Dialog</SfButton>

<SfDialog Width="250px" IsModal="true" CssClass="e-fixed" @bind-Visible="@IsVisible">
    <DialogEvents OnOverlayClick="@OnOverlayclick">
        <Content> This is a modal dialog </Content>
        <DialogButton Content="OK" IsPrimary="true" OnClick="@CloseDialog" />
        <DialogButton Content="Cancel" OnClick="@CloseDialog" />

@code {
    private bool IsVisible { get; set; } = true;

    private void OpenDialog()
        this.IsVisible = true;

    private void OnOverlayclick(MouseEventArgs arg)
        this.IsVisible = false;
    private void CloseDialog()
        this.IsVisible = false;
        height: 1200px;