从内容页面继承的xamarin基页中的导航为空

时间:2016-05-04 11:04:26

标签: .net xamarin xamarin.forms

我有一个继承自xamarin表单内容页面的BasePage,如下所示

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());
        }
    }

}
}

此页面中的所有剩余页面都是iherit,但由于空导航,当没有网络连接时,这会失败。请帮忙。 主页

    // The root page of your application
        MainPage = new SthotraaniMaster();

和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>

主页面只是菜单,神页面是继承自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);
        }
    }

1 个答案:

答案 0 :(得分:0)

从我的项目中删除XLabs表单后,它正在工作。现在导航不为空。