【发布时间】:2020-10-08 09:50:31
【问题描述】:
我有两个页面,假设 PageA 和 PageB(PageB 有一个名为 listview 的列表视图)。我想向 PageB 发送一个类对象。
MessagingCenter.Send<PageA, FooClass>(this, "foo", foo);
await Navigation.PushAsync(new PageB());
和 PageB 的 OnAppearing 方法类似(我使用 OnAppearing 我在 subscribe 方法中运行异步操作)
MessagingCenter.Subscribe<PageA, FooClass>(this, "foo", async (page, source) => {
listview.ItemSource = ...// Some method
});
MessagingCenter.Unsubscribe<ProfilesPage>(this, "Company");
尽管 listview.ItemSource 不为空,但 listview 不会填充。但是当我像
这样更改 PageA 的代码时await Navigation.PushAsync(new PageB());
MessagingCenter.Send<PageA, FooClass>(this, "foo", foo);
它有效。这有什么不对?
【问题讨论】:
-
我喜欢 MessagingCenter,但在这种情况下,通过它的构造函数将数据传递给
PageB会非常简单
标签: c# android listview xamarin xamarin.forms