Show an DisplayAlert at App.cs (Xamarin)

DisplayAlert is a method of the page class. However your app has a 'MainPage' property. So as long as the main page is set (should always be so after it's set during startup) you can use

Application.Current.MainPage.DisplayAlert

or from within App.cs

MainPage.DisplayAlert

So you can do this, is working for me

Device.BeginInvokeOnMainThread(async () => { await Application.Current.MainPage.DisplayAlert("No Internet Connection", "Please connect to Internet", "OK"); });

Tags:

C#

Xamarin