originally posted by: ianvink2
I built a hello world CAB app with 2 views. On 1 view I wired up an eventpublisher. But it never fires.
public event EventHandler OnAnnounce;
A button fires off OnAnnounce.
I listen for it in the another view
public void SomethingHappened(object sender, EventArgs e)
I add the views to the workspaces in the ModuleInit and they do display nicely:
public override void Load()
DealWorkItem myWorkItem = parentWorkItem.WorkItems.AddNew<DealWorkItem>();
myWorkItem.Run(parentWorkItem.Workspaces"workSpaceNormal", new SimpleView());
myWorkItem.Run(parentWorkItem.Workspaces"workSpaceExecutive", new ExecutiveView());
myWorkItem.Run(parentWorkItem.Workspaces"workSpaceReport", new ReportView());
Any idea why after this Load() event the myWorkItem.EventTopics.Count=0? And it appears never to fire as OnAnnounce is always null when I press the button to fire the event.
originally posted by: ianvink2
I think this is the reason:
I put an
EventPublication on an event in my presenter and it worked. Perhaps the CAB only looks at non-UI classes? It does makes sence since the heavy-lifting logic should be in the Presenter.
originally posted by: akol_dk
I think the reason is that you are creating the views yourselv using "new SimpleView()". In this way, CAB will not know about the creation of the view, so it will not know about the event publication.
If you create the view using:
SimpleView myView = WorkItem.SmartParts.AddNew<SimpleView>()
and then add it to the workspace using:
then CAB should know about the view, and event publication should work from the view.
Apart form this, you are right, business logic should be placed in the presenter and not the view.
originally posted by: ForeignerCR
Hello, my scenario is kind of similar but it's not working even though my
EventPublication is in the Controller (I'm using the MVC pattern).
I've done it before and it works very good, but this time something weird is happening and I can't figure out what.
Oppossed to this thread's subject, in my case WorkItem.EventTopic count is NOT 0, and actually it contains the EvenTopic I'm expecting to be fired. However the EventHandler is always null. So it's never fired if I compare it to null. If I manually fire the
event from the EventTopic collection, it actually fires and works perfectly.
Any idea of what's wrong? I'd really appreciate it.
public event EventHandler<DataEventArgs<myClass>> myEventTopic;
public void FireMyEventTopic(myClass mc)
// this condition is true and the invocation succeeds
WorkItem.EventTopics"event://myEventTopic".Fire(this, new DataEventArgs<myClass>(mc), this.WorkItem, PublicationScope.Global);
// this condition is always false, no Event is fired
if (myEvntTopic!= null)
myEventTopic(this, new DataEventArgs<myClass>(mc));
EventSubscription("event://myEventTopic", Thread = ThreadOption.UserInterface)
public void OnMyEventTopic(object sender, DataEventArgs<myClass> args)
myController.FireMyEventTopic(args.Data as myClass);
I create views and invoke Workitems in the way akol_dk wrote.
And I repeat, I've done it before and it works, so I'm lost this time.
Thanks in advance.