3

我有一个应用程序,它基于相同的视图和视图模型呈现许多视图-视图模型对。(即有很多视图-> viewModel 实例对)

我可以使用 Messenger 将消息从 viewModel 发送/注册到视图,当我从视图发送消息时,它会被所有视图处理(它们都注册消息)。

我将如何使用 Messenger 将消息从 viewModel 发送到创建 viewModel 的特定视图?(所有视图都注册了消息,但我只希望其中一个视图处理消息)

4

1 回答 1

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.

于 2012-05-25T03:26:07.640 回答