我给用户一个页面来编辑列表视图项目'内容。
$_POST
这是将用户带到那里的上下文操作。因此,在将用户发送到另一个页面后,我想等到他在编辑页面上完成编辑,然后返回完成该功能。
我打算以不同的方式做这件事,但事实并非我想要的方式。我需要public async void OnEdit(object sender, EventArgs e)
{
var menuItem = ((MenuItem)sender);
if (menuItem != null)
{
var selectedZone = (ViewModels.ZoneViewModel)menuItem.CommandParameter;
// Send to edit page with selectedzones' contents.
await Navigation.PushAsync(new ZonePage(selectedZone.Name, selectedZone.Address, selectedZone.IdentitySource, selectedZone.Username, selectedZone.Password));
//Wait until user returns from page
//Edit logic here
}
}
从列表中获取所选项目,并且不知道在我的情况下使其工作的另一种方法。
这可能吗?
答案 0 :(得分:1)
You can try MessagingCenter to communicate between two pages. Xamarin.Forms MessagingCenter enables view models and other components to communicate with without having to know anything about each other besides a simple Message contract.
To pass an argument with the message, specify the argument Type in the Subscribe generic arguments and in the Action signature.
MessagingCenter.Subscribe<MainPage, string> (this, "Hi", (sender, arg) => {
// do something whenever the "Hi" message is sent
// using the 'arg' parameter which is a string
});
To send the message with argument, include the Type generic parameter and the value of the argument in the Send method call.
MessagingCenter.Send<MainPage, string> (this, "Hi", "John");
Here is the more detailed official documentation with examples.