以下代码生成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的事件处理是不同的。请帮助我保持理智!
答案 0 :(得分:2)
问题在Exception
:Value cannot be null.
Parameter name: routedEvent
中解释。 RoutedEvent
是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