调用RoutedEvent时的ArgumentNullException

时间:2013-05-25 17:27:12

标签: wpf vb.net routed-events

以下代码生成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的事件处理是不同的。请帮助我保持理智!

1 个答案:

答案 0 :(得分:2)

问题在ExceptionValue cannot be null. Parameter name: routedEvent中解释。 RoutedEventRoutedEventArgs的属性。您必须提供正在筹集的RoutedEvent个实例,在您的情况下,它是PlayerDetailRequestedEvent。试试这段代码:

    Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
            Me.RaiseEvent(New RoutedPropertyChangedEventArgs(Of Player)(SelectedPlayer, SelectedPlayer, PlayerDetailRequestedEvent))
    End Sub