зеркало из https://github.com/telerik/blazor-docs.git
2.0 KiB
2.0 KiB
title | description | type | page_title | slug | position | tags | ticketid | res_type |
---|---|---|---|---|---|---|---|---|
Open a Window from another component | How to open a Window from another component? | how-to | Open a Window from another component | window-kb-open-from-another-component | telerik, blazor, window, open, show, another, page, component | kb |
Environment
Product | Window for Blazor |
Description
I want to make a separate razor page to hold the markup and code for the Window component and be able to open it from another page. How to achieve that?
Solution
You can get a reference to the component hosting the Window and use that to toggle the field that is bound to the Visible parameter of the window.
Another option would be to send such a reference as a cascading parameter if you have a more complex hierarchy and you need to go up and not down.
````MainPage.razor @* The page/component that you want to open the Window from *@caption Open a Window from another component
Toggle Window
<Window @bind-WindowIsVisible="@Visible">
@code { bool Visible { get; set; }
void ToggleWindow()
{
Visible = !Visible;
}
}
````Window.razor
@* Separate component hosting the markup and logic for the TelerikWindow *@
<TelerikWindow Visible="@WindowIsVisible" VisibleChanged="@WindowIsVisibleChanged">
<WindowTitle>
<strong>The Title</strong>
</WindowTitle>
<WindowContent>
This is my Window from another component.
</WindowContent>
<WindowActions>
<WindowAction Name="Minimize"></WindowAction>
<WindowAction Name="Maximize"></WindowAction>
<WindowAction Name="Close"></WindowAction>
</WindowActions>
</TelerikWindow>
@code {
[Parameter]
public bool WindowIsVisible { get; set; }
[Parameter]
public EventCallback<bool> WindowIsVisibleChanged { get; set; }
}