c# - 导航内容页面 MVVM xamarin
问题描述
有人可以教我如何在内容页面之间导航吗?我一直在阅读许多教程,但我无法实现它。我有这个小代码,我想在按下按钮时在页面之间切换。我使用 MVVM 模型有我的 MainViewModel
public class MainViewModel
{
public Page1 PageNumberOne { get; set; }
public Page2 PageNumberTwo { get; set; }
public MainViewModel()
{
this.PageNumberOne = new Page1();
}
}
有我的 Page1 视图模型
public class Page1
{
#region constructor
public Page1()
{
GoPage2Command = new Command(async () => await GoPage2());
}
private async Task GoPage2()
{
await Application.Current.MainPage.DisplayAlert("", "Goin to page 2", "ok");
//code to go PageNumberTwo here
}
#endregion
#region Commands
public Command GoPage2Command { get; set; }
#endregion
}
GoPage2Command 绑定到一个按钮。有我完整的项目上传到 MF VS proyect
解决方案
只需调用
Navigation.PushAsync(new ContentPage());
将 Page 异步添加到导航堆栈的顶部。
页面示例
var newPage = new ContentPage ();
await Navigation.PushAsync (newPage);
Debug.WriteLine ("the new page is now showing");
var poppedPage = await Navigation.PopAsync ();
Debug.WriteLine ("the new page is dismissed");
Debug.WriteLine (Object.ReferenceEquals (newPage, poppedPage)); //prints "true"
你的榜样
private async Task GoPage2()
{
await Application.Current.MainPage.DisplayAlert("", "Goin to page 2", "ok");
//code to go PageNumberTwo here
Navigation.PushAsync(new PageNumberTwo());
}
推荐阅读
- c# - WPF路径以某种大小消失
- google-app-engine - Google AppEngine 获取 403 禁止尝试更新 cron.yaml
- php - 使用 PHP 从字符串中提取特定数据
- php - 多个 ulpoad 文件中的数组到字符串错误
- c++ - 使用已删除的复制构造函数初始化抽象类
- java - 单独从 MQ 回复消息中获取 MSD ID
- xamarin - 如何将焦点设置为 xamarin 表单中的条目
- python - 使用“for in range(0,7,1)”比较两个列表
- python - django 中的 JsonResponse 和 HttpResponse 有什么区别
- html - 如何覆盖父框架的元视口?