我有一个带有freshmvvm 框架的Xamarin.Forms 应用程序。根据文档,我可以使用 FreshBasePageModel 基类的 PreviousPageModel 属性来访问我从中导航的 PageModel 的数据。我这样导航:
public FirstPageModel()
{
_validator = new CalculatorValidator();
CalculateCommand = new Command(execute: () =>
{
ValidationResult = _validator.Validate(this);
RaisePropertyChanged(nameof(ValidationResult));
if (ValidationResult.IsValid)
{
CoreMethods.PushPageModel<SecondPageModel>();
}
});
}
导航发生,但在 SecondPageModel 构造函数中,PreviousPageModel 为空:
public SecondPageModel()
{
_previousModel = (FirstPageModel)PreviousPageModel;
}
我究竟做错了什么?
谢谢你。
编辑:
我也试过:
public FirstPageModel()
{
_validator = new CalculatorValidator();
CalculateCommand = new Command(Calculate);
}
private void Calculate()
{
ValidationResult = _validator.Validate(this);
RaisePropertyChanged(nameof(ValidationResult));
if(ValidationResult.IsValid)
{
CoreMethods.PushPageModel<SecondPageModel>(this);
}
}