c# - Dealing with message loops in MVVM Light -
i have multiple objects in app both send , receive same message. example: column order of grid can changed when user drags , drops columns on grid, when user uses grid settings dialog , when user loads different report. grid can both send "column order changed" message , receive message.
is there way prevent grid getting own messages back? when user drags column around, grid sends "column order changed" message interested listeners, don't want grid call on subscription. use predicate , embed sender information in message wondering if mvvm light can handle scenario itself.
check out overload of imessenger register method:
/// <summary> /// registers recipient type of message tmessage. /// action parameter executed when corresponding /// message sent. see receivederivedmessagestoo parameter /// details on how messages deriving tmessage (or, if tmessage interface, /// messages implementing tmessage) can received too. /// /// <para> /// registering recipient not create hard reference it, /// if recipient deleted, no memory leak caused. /// </para> /// /// </summary> /// <typeparam name="tmessage">the type of message recipient registers /// for.</typeparam><param name="recipient">the recipient receive /// messages.</param><param name="token">a token messaging /// channel. if recipient registers using token, , sender sends /// message using same token, message delivered /// recipient. other recipients did not use token when /// registering (or used different token) not message. /// similarly, messages sent without token, or different /// token, not delivered recipient.</param><param name="receivederivedmessagestoo">if true, message types deriving /// tmessage transmitted recipient. example, if sendordermessage /// , executeordermessage derive ordermessage, registering ordermessage /// , setting receivederivedmessagestoo true send sendordermessage /// , executeordermessage recipient registered. /// /// <para> /// also, if tmessage interface, message types implementing tmessage /// transmitted recipient. example, if sendordermessage /// , executeordermessage implement iordermessage, registering iordermessage /// , setting receivederivedmessagestoo true send sendordermessage /// , executeordermessage recipient registered. /// </para> /// </param><param name="action">the action executed when message /// of type tmessage sent.</param> void register<tmessage>(object recipient, object token, bool receivederivedmessagestoo, action<tmessage> action);
note:
a token messaging channel. if recipient registers using token, , sender sends message using same token, message delivered recipient. other recipients did not use token when registering (or used different token) not message. similarly, messages sent without token, or different token, not delivered recipient.
what can have other registers of message register token, when grid sends message send token. grid's registration should not include token.
Comments
Post a Comment