开发者

Is it possible to send just a token via the MVVM Light Messenger?

I've been refactoring some code that was originally using the Messenger in MVVM Foundation to now use the Messenger in MVVM Light Toolit. One th开发者_运维问答ing that I can't seem to find an equivalent for is the case where all you want to do is send a Token (i.e, the Token is acting as both a unique identifier for the message and the message itself).

Original Code (MVVM Foundation) - one string does it all

// send code
mvvmFoundationMessenger.NotifyColleagues("QuestionTimedOut");

// register code
mvvmFoundationMessenger.Register(
    "QuestionTimedOut",
    () => UpdateOnQuestionTimedOut());

New Code (MVVM Light) - is there a more elegant solution than this?

// send code
mvvmLightMessenger.Send("QuestionTimedOut", "QuestionTimedOut");

// register code
mvvmLightMessenger.Register<string>(
    this,
    "QuestionTimedOut",
    token => UpdateOnQuestionTimedOut());

I realize I could explicitly new up a NotificationMessage but that would add even more code.


Good point. I put that on the backlog for MVVM Light VNext.


You could derive from MvvmLight's Messenger and add your own convenience methods or you could add Messenger Extension Methods in an extension class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜