Hi StevenManuel-7797,
Welcome to our Microsoft Q&A platform!
To show a error page while the service is not available, you don't need to create an extra Page "NoConnectivityPage".
Here is a workaround you can refer to.
Just define a Grid in your ReportsPage and create two StackLayout to show "Report" and "NoConnectivity". In this way, you only need to set the "IsVisible" property to switch the page.
<ContentPage.Content>
<Grid>
<StackLayout IsVisible="{Binding IsConnected}">
<Label Text="Report Page"
FontSize="50"/>
</StackLayout>
<StackLayout IsVisible="{Binding ShowErrorView}">
<Label Text="Error Page"
FontSize="50"/>
</StackLayout>
</Grid>
</ContentPage.Content>
Here is a simple demo that suppose an error page will be displayed when there is no network
class ReportViewModel : INotifyPropertyChanged
{
private bool isConnected;
public bool IsConnected
{
get => isConnected;
set
{
isConnected = value;
OnPropertyChanged("IsConnected");
}
}
private bool showErrorView;
public bool ShowErrorView
{
get => showErrorView;
set
{
showErrorView = value;
OnPropertyChanged("ShowErrorView");
}
}
public ReportViewModel()
{
IsConnected = true;
ShowErrorView = false;
CheckNetworkOnStart();
CheckNetwork();
}
public void CheckNetworkOnStart()
{
if (Connectivity.NetworkAccess == NetworkAccess.Internet)
{
IsConnected = true;
}
else
{
IsConnected = false;
}
ShowErrorView = !IsConnected;
}
public void CheckNetwork()
{
Connectivity.ConnectivityChanged += (sender, args) =>
{
if (Connectivity.NetworkAccess == NetworkAccess.Internet)
{
IsConnected = true;
}
else
{
IsConnected = false;
}
ShowErrorView = !IsConnected;
};
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
Code to open "ReportsPage".
Shell.Current.GoToAsync($"{nameof(ReportsPage)}");
Regards,
Kyle
If the response is helpful, please click "Accept Answer" and upvote it.
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.