title | description | type | page_title | slug | tags | res_type | ticketid |
---|---|---|---|---|---|---|---|
How To Center Window Programmatically |
Learn how to center a Telerik Window programmatically by using the Top and Left parameters. |
how-to |
How To Center Window Programmatically |
window-kb-center-programmatically |
window, center, position, blazor, |
kb |
Product | Window for Blazor |
This knowledge base article answers the following questions:
- How can I programmatically center a Telerik Window?
- How do I reset a Telerik Window to its default position?
- How can I position a Telerik Window in the center of the viewport?
- How do I dynamically adjust the Telerik Window position?
To center a Telerik Window programmatically, follow these steps:
- Use
Top
andLeft
parameters – These parameters define the Window position on the screen. - Reset
Top
andLeft
parameters to center the Window – Setting them tostring.Empty
allows automatic centering. - Refresh the Window using component reference – Calling
WindowRef?.Refresh();
re-renders the Window with the new position.
caption Telerik Blazor Window Centered Programmatically
@if (!IsWindowVisible)
{
<TelerikButton OnClick="@(() => IsWindowVisible = !IsWindowVisible)">Open Window</TelerikButton>
}
<TelerikButton OnClick="@CenterWindow">Center Window</TelerikButton>
<TelerikWindow @bind-Visible="@IsWindowVisible"
@bind-Top="@Top"
@bind-Left="@Left"
Width="200px"
Height="200px"
@ref="WindowRef">
<WindowTitle>
Window Title
</WindowTitle>
<WindowActions>
<WindowAction Name="Close" />
</WindowActions>
</TelerikWindow>
@code {
private TelerikWindow? WindowRef { get; set; }
private bool IsWindowVisible { get; set; } = true;
private string Top { get; set; } = "30%";
private string Left { get; set; } = "60%";
private void CenterWindow()
{
Top = Left = string.Empty;
WindowRef?.Refresh();
}
}
- Window Position
- Telerik Window for Blazor - Overview