I'm using the Composite Application Block in my app. There are 2 concepts, EventHandlers and CommandHandlers which seem very similar to me... both allow you to invoke functionality in one part of the UI from another. What is the difference between them?
Asked
Active
Viewed 78 times
1
-
are you asking in the general, i.e. abstract sense of the definitions, or are you asking about the specific context of commands/events in the CAB? – Josh E Jul 31 '12 at 19:59
1 Answers
1
I believe it is a matter of convenience. We use commands for buttons on a ribbon:
Public Sub AddElementToRibbonGroup(WorkItem As WorkItem, elementDescription As String, menuGroupKey As String, commandName As String, commandKey As String)
WorkItemController.ShellExtensionService.AddButtonToolExtension( _
WorkItem, _
commandKey, _
New ButtonToolAppearance(elementDescription), _
menuGroupKey, _
WorkItem.Commands(commandName))
End Sub
But we raise events from a form to handle logic in a controller:
sample_View.vb:
<EventBroker.EventPublication(Constants.Events.CreateNewNavTab, PublicationScope.Global)> _
Public Event CreateNewNavTab As EventHandler
' Node in Navigation Tree is double clicked
Private Sub NavTree_DoubleClick(sender As System.Object, e As System.EventArgs) Handles NavTree.DoubleClick
...
RaiseEvent CreateNewNavTab(Me, Nothing)
End Sub
sample_controller.vb:
' A new tab is created from the Nav Tree.
<EventSubscription(Constants.Events.CreateNewNavTab, ThreadOption.UserInterface)> _
Public Sub CreateNewNavTab(ByVal pNavView As Object, ByVal e As EventArgs)
...
End Sub
Hope this helps!

eniacAvenger
- 875
- 12
- 17