1

我在我的应用程序中使用复合应用程序块。有 2 个概念,EventHandlers 和 CommandHandlers 看起来与我非常相似……它们都允许您从 UI 的一个部分调用另一部分的功能。它们之间有什么区别?

4

1 回答 1

1

我相信这是一个方便的问题。我们对功能区上的按钮使用命令:

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

但是我们从表单中引发事件来处理控制器中的逻辑:

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

希望这可以帮助!

于 2014-03-10T22:21:53.483 回答