I have problem. I have code in MAUI -> Blazor.
In Blazor must be two buttons:
1 – create new window
2 – show alert in current window.
And Idk how to find current Window. if I use Application.Current.MainPage -> it’s will be reference to first window.
But I want show alert in current window.
example of code:
@page "/"
@using Microsoft.JSInterop
@using Microsoft.AspNetCore.Components.Web
@inject IJSRuntime JS
<div class="row">
<div class="col-md-4 mb-3">
<button class="btn btn-primary" @onclick="CreateNewWindow">Create new window</button>
</div>
<div class="col-md-4 mb-3">
<button class="btn btn-primary" @onclick="ShowAlert">Show alert!</button>
</div>
</div>
@code {
private async Task ShowAlert()
{
Page? currentWindow = Application.Current.MainPage;
if (currentWindow != null)
{
await currentWindow.DisplayAlert("Good", "Nice", "Test");
}
}
private async Task CreateNewWindow()
{
var newWindow = new Window(new MainPage());
(Application.Current as App).OpenWindow(newWindow);
}
}
How can I get instance of current window in which I click to button?
I expected that you help me)
New contributor
Maksym Shymchenko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.