开发者

How do you troubleshoot when Messenger Register not firing Action?

In code behind for a page:

Messenger.Default.Register(this, CheckWaitState);

and

private void CheckWaitState(string message) { //do something with message }

when a view model fires this:

Messenger.Default.Send(new NotificationMessage(开发者_StackOverflow中文版"", "some message..."));

...the above code is not hit. How do I troubleshoot?

Thanks


You're registering for a message of type 'string' but sending a message of type 'NotificationMessage'.

Try this:

Messenger.Default.Register<NotificationMessage>(this, CheckWaitState);

private void CheckWaitState(NotificationMessage message) 
{ 
    //do something with message.Notification 
    Console.WriteLine(message.Notification); // outputs "some message..."
}

Messenger.Default.Send(new NotificationMessage("", "some message..."));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜