C
C#•8mo ago
CG Seb

MAUI Popup at first start

Hi everyone, I created a MAUI app for windows (later mac), I would like to show a GCU popup at the first launch of the app. I tried to use the OnAppearing() of my Home page, but since it's not an async method, it doesn't wait for my popup. The popup only show if I go to another page and then go back to the home page 😦
C#
protected override void OnAppearing()
{
bool GCUAccepted = Preferences.Get(Constants.GCU_ACCEPTED_KEY, false);
if (!GCUAccepted)
{
GCUPopupPage page = new();
popupNavigation.PushAsync(page);
}

viewModel.LoadRecentsCommand.Execute("");
viewModel.LoadFavoritesCommand.Execute("");
base.OnAppearing();
}
C#
protected override void OnAppearing()
{
bool GCUAccepted = Preferences.Get(Constants.GCU_ACCEPTED_KEY, false);
if (!GCUAccepted)
{
GCUPopupPage page = new();
popupNavigation.PushAsync(page);
}

viewModel.LoadRecentsCommand.Execute("");
viewModel.LoadFavoritesCommand.Execute("");
base.OnAppearing();
}
Do you guys have any Idea on how to do this please?
1 Reply
Auger
Auger•7mo ago
Since OnAppearing is kind of an Event Handler of sorts, you can probably get away with making it an async void method. Generally, you wouldn't want to do that unless it is an event handler method. In this context you probably could to navigate.
protected override void void OnAppearing()
{
base.OnAppearing();

bool GCUAccepted = Preferences.Get(Constants.GCU_ACCEPTED_KEY, false);
if (!GCUAccepted)
{
GCUPopupPage page = new();
await popupNavigation.PushAsync(page);
}

// ....
}
protected override void void OnAppearing()
{
base.OnAppearing();

bool GCUAccepted = Preferences.Get(Constants.GCU_ACCEPTED_KEY, false);
if (!GCUAccepted)
{
GCUPopupPage page = new();
await popupNavigation.PushAsync(page);
}

// ....
}
Want results from more Discord servers?
Add your server