It would be nice to be able to configure a show/hide animation for windows.
ADMIN EDIT: This might include a form of a Shown event so that you could know when the content is rendered and available to, for example, focus a button or input. For more details see here
We are using a "TelerikWindow" that does neither contain the "WindowAction" "Minimize" nor "Maximize", since we do not want the user to do so. It is still possible, however, to minimize / maximize the window using the keyboard shortcuts described here: https://demos.telerik.com/blazor-ui/window/keyboard-navigation
We came up with a hack to work around the current behaivor:
The Window can display as centered, but after the user moves or resizes it, the app is not able to center the Window programmatically.
The only possible workaround is to toggle the Window's Visible parameter:
https://blazorrepl.telerik.com/weaewmFe32oT4rnQ42
<TelerikWindow @bind-Top="@Top" @bind-Left="@Left" Centered="@Centered" @bind-Visible="@Visible">
<WindowTitle>
Title
</WindowTitle>
<WindowContent>
Drag or resize the Window and center it afterwards...
</WindowContent>
</TelerikWindow>
<TelerikButton OnClick="@( () => Visible = !Visible )">Toggle Window</TelerikButton>
<TelerikButton OnClick="@OnCenterClick">Center</TelerikButton>
@code {
string Top { get; set; }
string Left { get; set; }
bool Centered = false;
bool Visible { get; set; } = true;
async Task OnCenterClick()
{
Visible = false;
await Task.Delay(1);
Top = Left = string.Empty;
Visible = true;
}
}
I would like to have an event that fires when the user closes the Window and to be able to cancel the event. I would like to have an identifier if the user pressed the "Esc" key or the Close button rendered in the Browser.
---
ADMIN EDIT
---
At the time of writing, only using the VisibleChanged event can let you prevent the Window from closing. As a workaround, you can cancel this event and use a custom close command that will not trigger it to, effectively, disable closing with Esc: https://blazorrepl.telerik.com/GcaqOxkT13mCiQ4q33.
---
admin edit
At the moment this is not guaranteed and if you want to customize the behavior you should use a custom action to get the OnClick handler, and control the window through its parameters.
Here is an example of implementing a custom close button that also fires an event:
<TelerikWindow Visible="@IsWindowVisible" Modal="true" Centered="true">
<WindowTitle>WindowTitle</WindowTitle>
<WindowContent>
lorem ipsum
</WindowContent>
<WindowActions>
<WindowAction Name="MyCustomAction" Icon="close" OnClick="@HandleCancel" />
</WindowActions>
</TelerikWindow>
@code{
bool IsWindowVisible { get; set; } = true;
async Task HandleCancel()
{
Console.WriteLine("my custom click happened");
IsWindowVisible = false;//hide the window with your own code if you also want to do that
}
}
---
Can we please have an [Open] or [Init] or [OnVisible] event exposed for Blazor Windows?
There is a whole bunch of stuff that I need to do in a Window (e.g. custom modal editing form that needs a lot of temporary supporting data structures) and I am having to do the work in a method that that opens the window, before the Window is opened and passing many data structures to the Window as parameters (there could be more than 20 of these). This is messy.
It would be much simpler, neater and efficient to have the Window create these resources on the fly when the Window is made visible and to dispose of them when the window closes. I would then only need to pass a few essential parameters.
I'm guessing this is a new feature request because I cannot see any way of detecting, in the code for a Window, that it has just been opened (or am I missing something?).
Kind regards,
Paul