Search code examples
c#blazorblazor-server-sidemudblazor

MudBlazor: Prevent close when clicking outside dialog (on overlay)


Is it possible to prevent closing the MudBlazor dialog when clicking on the overlay (outside the dialog)? Or to run a Task when clicking on the overlay?


Solution

  • To prevent closing the dialog when clicking on the overlay, you need to set DisableBackdropClick = true

    For example:

    @inject IDialogService DialogService
    
    <MudButton OnClick="@((e) => OpenDialog())"
               Variant="Variant.Filled"
               Color="Color.Primary">Show Dialog</MudButton>
    
    @code 
    {
        private void OpenDialog()
        {   
            DialogOptions options = new DialogOptions() { DisableBackdropClick = true };
            DialogService.Show<DialogUsageExample_Dialog>("Custom Options", options);
        }
    }