-
Notifications
You must be signed in to change notification settings - Fork 81
docs(Window): add kb for programmatic center of the window #2821
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a08053d
docs(Window): add kb for programmatic center of the window
Tsvetomir-Hr ae5b283
chore: update kb content
Tsvetomir-Hr 699e424
Update knowledge-base/window-center-programmatically.md
Tsvetomir-Hr 8e71fe6
Update knowledge-base/window-center-programmatically.md
Tsvetomir-Hr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
Tsvetomir-Hr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| >caption Telerik Blazor Window Centered Programmatically | ||
Tsvetomir-Hr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ````RAZOR | ||
| @if (!IsWindowVisible) | ||
Tsvetomir-Hr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| <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%"; | ||
Tsvetomir-Hr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.