tags:

views:

62

answers:

3

I got this code from msdn http://code.msdn.microsoft.com/eventbehaviourfactor

I have most of it converted but having an issue with the following sub getting it converted correctly

 Protected Overrides Sub AdjustEventHandlers(ByVal sender As DependencyObject, ByVal oldValue As Object, ByVal newValue As Object)
                Dim element As UIElement = TryCast(sender, UIElement)
                If element Is Nothing Then
                    Return
                End If

                If oldValue IsNot Nothing Then
                    element.[RemoveHandler](_routedEvent, New RoutedEventHandler(EventHandler))
                End If

                If newValue IsNot Nothing Then
                    element.[AddHandler](_routedEvent, New RoutedEventHandler(EventHandler))
                End If
            End Sub

I didnt want to put the whole class in the post but the above link takes you to the code in C# EventBehaviourFactory This is the class I am trying to convert.

Thanks you!

+1  A: 

use : http://www.developerfusion.com/tools/convert/vb-to-csharp/

Pranay Rana
I thought he was trying to convert to VB .NET, not C#
BlueMonkMN
You are correct I am trying to get it to VB.NET. I used that converter to get me 3/4 the way and just had a couple parts I had to figure out. Thanks for the response.
spafa9
+1  A: 
protected override void AdjustEventHandlers(DependencyObject sender, object oldValue, object newValue)
{
    var element = sender as UIElement;
    if (element == null) {
        return;
    }

    if (oldValue != null) {
        element.RemoveHandler(_routedEvent, new RoutedEventHandler(EventHandler));
    }

    if (newValue != null) {
        element.AddHandler(_routedEvent, new RoutedEventHandler(EventHandler));
    }
}
Vash
figured it out I needed to put AddressOf in front of the EventHandler. Thanks for you help
spafa9
A: 

I think you need to add "AddressOf" before each occurrence of "EventHandler" when constructing RoutedEventHandler.

  If oldValue IsNot Nothing Then
     element.[RemoveHandler](_routedEvent, New RoutedEventHandler(AddressOf EventHandler))
  End If

  If newValue IsNot Nothing Then
     element.[AddHandler](_routedEvent, New RoutedEventHandler(AddressOf EventHandler))
  End If
BlueMonkMN