How to send message to one view of many

孤街醉人 提交于 2019-12-10 20:42:34

问题


I have an app that presents many view-viewModel pairs based on the same view and viewModel. (ie there are many view -> viewModel instance pairs)

I can use the Messenger to send/register messages from viewModel to view, and when I send a message from a view, it is processed by all the views (They all register for the message).

How would I use the Messenger to send a message from the viewModel to the specific view that created the viewModel? (All the views have registered for the message, but I only want one of the views to process the message)


回答1:


You can use the Token while sending and registering Messaging.

Suppose You have to pass Message From ViewModel to ABCView then you can use Messenging like this..

For Ex, if you have to pass boolean value then use:

Messenger.Defalut.Send<bool>(true,"ForAbcView");

And in ABCView you can register like this:

Messenger.Default.Register<bool>(this,"ForAbcView",(b)=>{ //Some Code });

With using Token the Messenger Sender will only looks for the Register which will have same token. It only calls the method which will have same tocken.



来源:https://stackoverflow.com/questions/10133083/how-to-send-message-to-one-view-of-many

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!