我正在尝试将数据从MainActivity发送回PCL视图。当我发送一条没有数据的消息时,它会接收它。但是,当我试图用它传递回一个字符串时,代码永远也达不到。
在MainActivity中:
if(data != null)
{
MessagingCenter.Send<object, string>(this, data, "MapIntentReceived");
MessagingCenter.Send<object>(this, "MapIntentReceived");
}在PCL中:
MessagingCenter.Subscribe<object, string>(this, "MapIntentReceived",
async (sender, roomString) =>
{ //his code is not reached
await SearchForRooms(roomString);
});
MessagingCenter.Subscribe<object>(this, "MapIntentReceived",
async (sender) =>
{ //this code is reached
await SearchForRooms("blah");
});谢谢你的帮助。
发布于 2017-08-18 00:58:29
若要发送带有参数的消息,请在send方法调用中包括Type泛型参数和参数的值。
MessagingCenter.Send<MainPage, string> (this, "MapIntentReceived", data);若要在消息中传递参数,请在订阅泛型参数和操作签名中指定参数类型。
MessagingCenter.Subscribe<MainPage, string> (this, "MapIntentReceived", (sender, arg) => {
await SearchForRooms(arg);
});对于取消订阅
MessagingCenter.Unsubscribe<MainPage, string> (this, "MapIntentReceived");https://stackoverflow.com/questions/45740892
复制相似问题