以下代码显示了OpenPage Command
的2个示例。 MainPageModel
中的一个有效,因为它直接来自FreshBasePageModel
。但是,ChildPageModel
中的第二个OpenPage调用将无法工作(或编译)。我不想到处传递父模型。那么,如何使用FreshMVVM从ChildPageModel
打开新页面(并使后退按钮起作用,等等)?
public class MainPageModel : FreshBasePageModel
{
public Command OpenPage
{
get
{
return new Command(() =>
{
CoreMethods.PushPageModel<NewPageModel>();
});
}
}
public ChildPageModel ChildPageModel { get; set; }
}
public class ChildPageModel
{
public Command OpenPage
{
get
{
return new Command(() =>
{
// ??????
CoreMethods.PushPageModel<NewPageModel>();
});
}
}
}
答案 0 :(得分:0)
还应该使ChildPageModel继承自FreshBasePageModel。所有PageModels都应继承自FreshBasePageModel
答案 1 :(得分:0)
我用三个页面(MainPage,SecondPage,ThirdPage)做一个简单的例子。您可以从HitHub下载FreshMVVMDemo文件夹的源文件。 https://github.com/WendyZang/Test.git
如果要打开新页面,可以在子页面中添加命令。
#region Commands
public Command GotoPageCommand
{
get
{
return new Command(async () =>
{
await CoreMethods.PushPageModel<ThirdPageModel>(); //replace the ThirdPageModel with the page you want to open
});
}
}
#endregion
如果要返回,请添加以下命令。
#region Commands
public Command GoBackSecondCommand
{
get
{
return new Command(async () =>
{
//await CoreMethods.PopPageModel(); //go back to main page
await CoreMethods.PushPageModel<SecondPageModel>(); //Go back to third page
});
}
}
#endregion
答案 2 :(得分:0)
以下代码将完成此任务...
z[] <- ifelse(is.infinite(z), NA, z)