Back to Devexpress

DxWindow.ShowAsync(CancellationToken) Method

blazor-devexpress-dot-blazor-dot-dxwindow-dot-showasync-x28-system-dot-threading-dot-cancellationtoken-x29.md

latest3.3 KB
Original Source

DxWindow.ShowAsync(CancellationToken) Method

Asynchronously shows the Window.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public Task<bool> ShowAsync(
    CancellationToken token = default(CancellationToken)
)

Optional Parameters

NameTypeDefaultDescription
tokenCancellationTokennull

An object that propagates a cancellation notification.

|

Returns

TypeDescription
Task<Boolean>

An asynchronous operation that shows 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.

razor
@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 the ShowAsync and CloseAsync 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

DxWindow Class

DxWindow Members

DevExpress.Blazor Namespace