Xamarin.Forms: 导航到页面失败

Xamarin.Forms: Navigation to a page failed

我在使用 Xamarin 的第一个应用程序中发现页面导航有困难。到处研究,第一次用导航就成功了。

但是当我添加一个按钮时,需要导航的页面构建器被调用但没有打开任何页面。当我点击我曾经工作过的按钮时(根据下面的打印列出)它会出现,但我注意到点击设备 Windows Phone 硬件按钮点击第一个失败即它应该是另一个页面堆栈。我不知道如何解决,因为在这第二个按钮中工作正常但第一个无法解决并且找不到可能是什么问题。

使用 Windows Phone 项目测试和使用 Visual Studio 2015 社区。

按钮截图:

MainViewModel.cs 设置通过点击按钮绘制导航的命令在哪里:

private readonly INavigationService _navigationService;

public MainViewModel()
{
        RescisaoCommand = new Command(NavigateToRescisao);
        FGTSCommand = new Command(NavigateToFGTS);

        _navigationService = DependencyService.Get<INavigationService>();
}

private async void NavigateToRescisao()
{
        await _navigationService.NavigateToRescisao();
}

private async void NavigateToFGTS()
{
        await _navigationService.NavigateToFGTS();
}

App.cs构造函数:

public App()
{
     DependencyService.Register<IMessageService, MessageService>();
     DependencyService.Register<INavigationService, NavigationService>();

     // The root page of your application
     MainPage = new NavigationPage(new MainView());
}

INavigationService.cs接口:

public interface INavigationService
{
    Task NavigateToRescisao();
    Task NavigateToFGTS();
}

NavigationService.cs:

public class NavigationService : INavigationService
{
    public async Task NavigateToRescisao()
    {
        await App.Current.MainPage.Navigation.PushAsync(new RescisaoView());
    }

    public async Task NavigateToFGTS()
    {
        await App.Current.MainPage.Navigation.PushAsync(new FGTSView());
    }
}

FGTSViewModel.cs 构造函数(有效):

public FGTSViewModel()
{
     CalculateFgtsCommand = new Command(x => { ShowResult(); });

     _messageService = DependencyService.Get<IMessageService>();
     //_navigationService = DependencyService.Get<INavigationService>();
}

RescisaoViewModel.cs 构造函数(无效):

 public RescisaoViewModel()
 {
       Reasons = new List<string>();
       TypesOfNotice = new List<string>();

       Reasons.Add("Pedido de demissão");
       Reasons.Add("Justa causa");
       Reasons.Add("Sem justa causa");
       Reasons.Add("Término de contrato de experiência");

       TypesOfNotice.Add("Trabalhado");
       TypesOfNotice.Add("Indenizado");

       //_navigationService = DependencyService.Get<INavigationService>();
 }

他设法解决了 problem.I 检查我的绑定,它们是不完整的名称。

问题是有一个错误描述可以帮助我,我相信这可以为其他人服务。