0

I have to add event setter to a style in code behind file in VB.NET.

While adding event setter we have to pass 2 arguments.

  1. is system.windows.routedevent
  2. system.delegate.

I am unable to pass system.delegate.

Ignacio Correia
  • 3,611
  • 8
  • 39
  • 68
user1508503
  • 41
  • 1
  • 4

1 Answers1

0

You need to define a Delegate with the correct signature first:

Delegate Sub HandlerDelegate(ByVal sender As Object, ByVal e As RoutedEventArgs)

Then create a method in your class matching that signature

Private Sub MyHandler(ByVal sender As Object, ByVal e As RoutedEventArgs)

End Sub

Now you can define a variable of HandlerDelegate type, assign your method to it and pass it to EventSetter constructor:

Dim handler As HandlerDelegate
handler = AddressOf Me.MyHandler

Dim setter As EventSetter
setter = New EventSetter(routedEvent, handler)
Damir Arh
  • 17,637
  • 2
  • 45
  • 83