-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(Window): add kb for programmatic center of the window #2821
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,78 @@ | ||||||
--- | ||||||
title: How To Center Window Programmatically | ||||||
description: Learn how to center a Telerik Window programmatically by using the Top and Left parameters. | ||||||
type: how-to | ||||||
page_title: How To Center Window Programmatically | ||||||
slug: window-kb-center-programmatically | ||||||
tags: window, center, position, blazor, | ||||||
res_type: kb | ||||||
ticketid: | ||||||
--- | ||||||
|
||||||
## Environment | ||||||
<table> | ||||||
<tbody> | ||||||
<tr> | ||||||
<td>Product</td> | ||||||
<td>Window for Blazor</td> | ||||||
</tr> | ||||||
</tbody> | ||||||
</table> | ||||||
|
||||||
## Description | ||||||
|
||||||
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? | ||||||
|
||||||
## Solution | ||||||
|
||||||
To center a Telerik Window programmatically, follow these steps: | ||||||
|
||||||
1. Use [`Top` and `Left` parameters](slug:components/window/position#top-and-left) – These parameters define the Window position on the screen. | ||||||
2. Reset `Top` and `Left` parameters to center the Window – Setting them to `string.Empty` allows automatic centering. | ||||||
3. Refresh the Window using component reference – Calling `WindowRef?.Refresh();` re-renders the Window with the new position. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
||||||
>caption Telerik Blazor Window Centered Programmatically | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the caption an action "verb", rather than a "noun". For example:
Suggested change
|
||||||
|
||||||
````RAZOR | ||||||
@if (!IsWindowVisible) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example can be simplified:
|
||||||
{ | ||||||
<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(); | ||||||
} | ||||||
} | ||||||
```` | ||||||
|
||||||
## See Also | ||||||
- [Window Position](slug:components/window/position) | ||||||
- [Telerik Window for Blazor - Overview](slug:window-overview) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This step is not actionable, especially if the customer wants the Window to be initially centered. For example, explain:
This may also help you to make the next step simpler, because the reader will already be familiar with the
string.Empty
value.