Hello,
=================Update=================
Please do not remove e.Cancel = true;
in the Closing event like following code.
appWindow.Closing += async (s, e) =>
{
e.Cancel = true;
bool answer = await Application.Current.MainPage.DisplayAlert("Question?", "Would you like to play a game", "Yes", "No");
if (answer)
{
}
else{
App.Current.Quit();
}
}
bool answer = await DisplayAlert("Question?", "Would you like to play a game", "Yes", "No"); not complied in maui program/create maui app
You can use Application.Current.MainPage.DisplayAlert
to invoke the DisplayAlert
in maui program/create maui app like following code.
bool answer = await Application.Current.MainPage.DisplayAlert("Question?", "Would you like to play a game", "Yes", "No");
if (answer)
{
}
else{
App.Current.Quit();
}
Best Regards, Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.