Publishing event from Shell Form

Topics: CAB & Smart Client Software Factory
Jan 11, 2006 at 3:08 PM
originally posted by: WateryDan

Hi, is it possible to publish an event in shell form so all event subscribers can respond to that? I've tried to create an EventHandler but it is always Null. Seems the EventHandler isn't getting registered properly in CAB.

Edit: In fact, the EventHandler is within a UserControl that's being included in the ShellForm. The UserControl isn't part of a WorkItem so I guess that might be the issue. How do I publish an event through a normal UserControl that's not part of CAB?
Jan 11, 2006 at 3:20 PM
originally posted by: mhildner

I've done this and things seem to work just fine. This is the code in the shell form:

/// <summary>
/// Event that is broadcasted when the connection status changes.
/// </summary>
EventPublication("event://ConnectionStatusChanged", PublicationScope.Global)
public event EventHandler ConnectionStatusChanged;

Then I raise that via

/// <summary>
/// Called by the UpdateState method in the ConnectionManagementController.
/// </summary>
/// <param name="state"></param>
public void UpdateState(NetworkConnectionState state)
this.ConnectionStatusChanged(this, new StateChangedEventArgs("ConnectionState", state));

A subscriber (in this case a WorkItem) listens to this event with:

public void ConnectionStatusChanged(object sender, StateChangedEventArgs e)
MessageBox.Show(e.NewValue.ToString(), e.Key);

I'm no CAB expert, but this seems to work ok <s>


Edit because I saw your edit <g>. The posted EventPublication is within the shell form itself, and not in a UserControl.
Jan 11, 2006 at 4:29 PM
originally posted by: RolandLi

You should create your UserControl by using the .AddNew<your UserControll class> method of WorkItem .Then the class will be build by the ObjectBuilder and added into the item list.
Once your object is create through an objectBuilder ,the Attribute (in this case,the attribute decorating the EventHandler) will be analysed and registered.
Jan 11, 2006 at 6:30 PM
originally posted by: WateryDan

Thanks Roland!

Because I create the UserControl at runtime and add it to the shell form, how can I get the user control out from the workitem and attach it to the form? I want the usercontrol to be a normal control and not be displayed within a workspace. Is it possible?
Jan 11, 2006 at 6:38 PM
originally posted by: WateryDan

I got it! You can get the UserControl back from the item list by calling