Shi*_*nga 2 xamarin.ios xamarin xamarin.forms
询问这个问题的原因是,当我在 xamarin 表单 mvvm 架构中使用 PushAsync 时出现错误
await Navigation.PushAsync(new Page2());
Run Code Online (Sandbox Code Playgroud)
错误是
我已通过将 PushAsync 更改为 PushModelAsync 纠正了此错误
await Navigation.PushModalAsync(new Page2());
Run Code Online (Sandbox Code Playgroud)
有人知道这个错误的原因是什么吗?
我正在从 ViewModel 调用 PushModelAsync
public class Page1Model : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public INavigation Navigation { get; set; }
public Command ContinueBtnClicked { get; }
public Page1Model(INavigation navigation)
{
this.Navigation = navigation;
this.ContinueBtnClicked = new Command(async () => await GotoPage2());
}
public async Task GotoPage2()
{
await Navigation.PushModalAsync(new Page2());
}
}
Run Code Online (Sandbox Code Playgroud)
将您的App.xaml.cs
第一页包装在 中NavigationPage
,如下所示:MainPage = new NavigationPage(new Page1());
。
现在它会起作用了。如果你只有一个页面,iOS 不知道如何从那里导航到另一个页面,因此它需要一个容器页面来处理导航。
模态变体起作用的原因是它产生了一个新的导航堆栈并在其他所有内容之上显示页面(因此是模态的)。
归档时间: |
|
查看次数: |
6091 次 |
最近记录: |