I have a BasePage which is inherited from xamarin forms contentpage as below
using Xamarin.Forms;
using XLabs.Ioc;
using XLabs.Platform.Device;
using XLabs.Platform.Services;
namespace Sthotraani.Views
{
public partial class BasePage : ContentPage
{
public IDevice XDevice;
public BasePage()
{
XDevice = Resolver.Resolve<IDevice>();
EnsureConnection();
}
public async void EnsureConnection()
{
if (XDevice.Network.InternetConnectionStatus() == NetworkStatus.NotReachable)
{
await Navigation.CheckNPushModal(new NoNetworkPage());
}
}
}
}
All remaining pages iherit from this page, but due to null navigation this fails when there's no network connection. Please help. Main page
// The root page of your application
MainPage = new SthotraaniMaster();
and xaml
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Sthotraani.Views;assembly=Sthotraani"
x:Class="Sthotraani.Views.SthotraaniMaster" >
<MasterDetailPage.Master>
<local:MasterPage x:Name="masterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage BarBackgroundColor="#00796B" BarTextColor="White" >
<x:Arguments>
<local:GodsPage />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
Master page is just menu, gods page is the content page which inherits from BasePage
public static async Task<Page> CheckNPopModal(this INavigation navigation, Page p)
{
Page rp = null;
if (navigation.ModalStack.Any(m => m.GetType() == p.GetType()))
{
rp = await navigation.PopModalAsync(true);
}
return rp;
}
public static async Task CheckNPushModal(this INavigation navigation, Page p)
{
if (!navigation.ModalStack.Any(m => m.GetType() == p.GetType()))
{
await navigation.PushModalAsync(p,true);
}
}