1

以下代码产生 ArgumentNullException:

Public Custom Event PlayerDetailRequested As RoutedPropertyChangedEventHandler(Of Player)

    AddHandler(ByVal value As RoutedPropertyChangedEventHandler(Of Player))
        Me.AddHandler(PlayerDetailRequestedEvent, value)
    End AddHandler

    RemoveHandler(ByVal value As RoutedPropertyChangedEventHandler(Of Player))
        Me.RemoveHandler(PlayerDetailRequestedEvent, value)
    End RemoveHandler

    RaiseEvent(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Player))
        Me.RaiseEvent(e)
    End RaiseEvent
End Event

Public Shared ReadOnly PlayerDetailRequestedEvent As RoutedEvent = _
                  EventManager.RegisterRoutedEvent("PlayerDetailRequested", _
                  RoutingStrategy.Bubble, _
                  GetType(RoutedPropertyChangedEventHandler(Of Player)), GetType(PlayersManagementControl))



  Private Sub Hyperlink_Click(sender As Object, e As RoutedEventArgs)
        RaiseEvent PlayerDetailRequested(Me, New RoutedPropertyChangedEventArgs(Of Player)(SelectedPlayer, SelectedPlayer))
    End Sub

调用时抛出异常Me.RaiseEvent(e)

在 VB 中很难找到工作示例,而 C sharp 的事件处理不同。请帮助我保持理智!

4

1 回答 1

2

该问题在Exception:中进行了解释Value cannot be null. Parameter name: routedEventRoutedEvent是 a 的属性RoutedEventArgs。您必须提供RoutedEvent您正在提出的实例,在您的情况下是PlayerDetailRequestedEvent. 试试这段代码:

    Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
            Me.RaiseEvent(New RoutedPropertyChangedEventArgs(Of Player)(SelectedPlayer, SelectedPlayer, PlayerDetailRequestedEvent))
    End Sub
于 2013-05-25T19:49:46.607 回答