Jeremy
Jeremy

Reputation: 179

MudBlazor: Run Task when clicking on backdrop

The backdrop click can be disabled with MudBlazor dialog. But how to run a Task when clicking on the backdrop?

Upvotes: 0

Views: 448

Answers (1)

RBee
RBee

Reputation: 4967

You have to use the OnBackdropClick EventCallback.

For this to work the DisableBackdropClick option should Not be true. However if you implement your own logic/Task when backdrop is clicked, this will override the default logic for backdrop click, which is to close/cancel the dialog.

<MudDialog OnBackdropClick="@HandleBackdropClick">
    <TitleContent>
        <p>Times backdrop clicked: @timesBackDropClicked</p>
    </TitleContent>
</MudDialog>

@code {
    [CascadingParameter] MudDialogInstance MudDialog { get; set; }
    int timesBackDropClicked;
    void HandleBackdropClick(MouseEventArgs eArgs)
    {
        timesBackDropClicked++;
    }
}

mudblazor snippet

Upvotes: 0

Related Questions