Skip to main content

DxWindow.CloseAsync(CancellationToken) Method

Asynchronously closes the Window.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public Task<bool> CloseAsync(
    CancellationToken token = default(CancellationToken)
)

Optional Parameters

Name Type Default Description
token CancellationToken null

An object that propagates a cancellation notification.

Returns

Type Description
Task<Boolean>

An asynchronous operation that closes the Window.

Remarks

Call the ShowAsync and CloseAsync methods to show and close the Window asynchronously. Make sure the component has been initialized before you call the ShowAsync method. Use the IsInitialized property to check the initialization state.

@inject IJSRuntime JsRuntime

<DxButton RenderStyle="ButtonRenderStyle.Primary" Text="Show" Click="ShowClick" />

<DxWindow @bind-Visible="@WindowVisible"
         HeaderText="Header"
         BodyText="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sit amet metus vel
             nisi blandit tincidunt vel efficitur purus. Nunc nec turpis tempus, accumsan orci auctor,
             imperdiet mauris. Fusce id purus magna."
         ShowFooter="true"
         @ref="Window">
    <FooterTemplate>
        <DxButton RenderStyle="ButtonRenderStyle.Primary" Text="Close" Click="CloseClick" />
    </FooterTemplate>
</DxWindow>

@code {
    DxWindow Window;
    bool WindowVisible { get; set; } = false;

    async Task ShowClick(MouseEventArgs args)
    {
        if (Window.IsInitialized)
            await Window.ShowAsync();
        else
            await JsRuntime.InvokeVoidAsync("alert", "The component has not been initialized yet. Please try later.");
    }

    async Task CloseClick(MouseEventArgs args)
    {
        await Window.CloseAsync();
    }
}

You can handle the following events related to these methods:

  • Showing - Fires before the Window is displayed and allows you to cancel this action.
  • Shown - Fires after the Window is displayed.
  • Closing - Fires before the Window is closed and allows you to cancel this action.
  • Closed - Fires after the Window is closed.

To show and close the Window synchronously, implement two-way binding for the Visible property.

See Also