Widget Communication

Posted on 5/18/2012 | Printable Version | Comments (0)

Waypoint provides a means for widgets to communicate with one another. Any widget you create can submit a message to the Waypoint framework with a command name and some data. Other widgets on the page can subscribe to this event. This page describes how you can code to use this feature.

Sending Messages

To send a message to other widgets, you can cast the current page as WPPageLite and call the OnActionDistributed method. You will pass "this" as a sender reference, and a WPControlEventArgs object with the details of your message. This object includes a command name string and an optional object that you can use to pass along parameter data.
((WPPageLite)Page).OnActionDistributed(this, new WPControlEventArgs("COMMAND_NAME_HERE", OptionalDataObject));

Listening For Messages

To listen for messages, you need to add an event handler. 
//IN THE ONINIT STAGE, ADD AN EVENT HANDLER TO THE ACTIONDISTRIBUTED EVENT.
protected override void OnInit(EventArgs e)
{
   ((WPPageLite)Page).ActionDistributed += new WPPageLite.DistributeAction(FormBuilder_ActionDistributed);
   base.OnInit(e);
}

//IN THE EVENT HANDLER METHOD, CHECK FOR A DATA TRANSFER STRING WITH THE COMMAND NAME
void FormBuilder_ActionDistributed(object sender, WPControlEventArgs e) {   if (e.CommandName == "COMMAND_NAME_HERE")     {          //PERFORM SOME ACTION HERE //e.DataTransfer may contain an object.     }
}


Comments

Be the first to comment below.

Post Comment