我在使用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());
}
NavigationService.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>();
}
他设法解决了这个问题。我检查了绑定,但它们的名称不完整。
问题是有一个错误说明可以帮助我,我相信这可以为其他人服务。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句