我正在开发 xamarin PCL 表单应用程序,我试图将数据从内容页面发送到选项卡页面。这里我有下面的内容页面代码
private async void StudentList_ItemTapped(object sender, ItemTappedEventArgs e)
{
var student = StudentList.SelectedItem as Students;
if (student != null) {
var mainViewModel = BindingContext as StudentsViewModel;
if (mainViewModel != null) {
mainViewModel.SelectedStudent = student;
await Navigation.PushAsync(new ProfilePage(mainViewModel));
}
}
}
现在,这个 ViewModel 具有实现了 getter 和 setter 方法的属性,这些方法正在获取价值。我在这段代码中的逻辑是从列表中设置选定项的值并获取选定人员数据的对象。并在标签页上访问该人的数据以在个人资料中显示。
下面 id tabbed-page.cs
public partial class ProfilePage : TabbedPage
{
public ProfilePage()
{
InitializeComponent();
}
public ProfilePage(StudentsViewModel mainViewModel)
{
InitializeComponent();
BindingContext = mainViewModel;
}
}
如果您看到当您将视图模型(具有设置对象值的属性)传递给参数时,可以通过将其设置为绑定上下文并通过将参数值设置为来在另一个内容页面上访问它来访问它来获取选定的项目值与传递的视图模型相同。
在这里,我的问题是,当我使用内容页面到标签页而不是内容页面到内容页面时,如何实现相同的技术。
在此先感谢,如果您不知道或者您是我想在这里讨论的内容,请告诉我。