How to convert anonymous method to VB.NET

I have the following in C #:

public static void StartAnimation(UIElement animatableElement, DependencyProperty dependencyProperty, double toValue, double animationDurationSeconds, EventHandler completedEvent) { double fromValue = (double)animatableElement.GetValue(dependencyProperty); DoubleAnimation animation = new DoubleAnimation(); animation.From = fromValue; animation.To = toValue; animation.Duration = TimeSpan.FromSeconds(animationDurationSeconds); //// HERE ---------------------------------------------------- animation.Completed += delegate(object sender, EventArgs e) { // // When the animation has completed bake final value of the animation // into the property. // animatableElement.SetValue(dependencyProperty, animatableElement.GetValue(dependencyProperty)); CancelAnimation(animatableElement, dependencyProperty); if (completedEvent != null) { completedEvent(sender, e); } }; 

I have some problems converting an anonymous method to VB.NET.

My option would be

  AddHandler animation.Completed, Function(sender As Object, e As EventArgs) As Boolean ' ' ' When the animation has completed bake final value of the animation ' ' into the property. ' ' animatableElement.SetValue(dependencyProperty, animatableElement.GetValue(dependencyProperty)) CancelAnimation(animatableElement, dependencyProperty) completedEvent(sender, e) Return True End Function 

I added Function As Boolean , because without a return type it is not a function, but creating a β€œSub” I don’t know how ...

Some tips?

+4
source share
2 answers

The syntax for anonymous methods is as follows:

 AddHandler animation.Completed, _ Sub(sender As Object, e As EventArgs) ' ' ' When the animation has completed bake final value of the animation ' ' into the property. ' ' animatableElement.SetValue(dependencyProperty, animatableElement.GetValue(dependencyProperty)) CancelAnimation(animatableElement, dependencyProperty) completedEvent(sender, e) End Sub 

However, you need VB10 to be able to use this; previous versions do not yet support this.

+5
source

make it sub.

 Public SUB <method name>(<parameters>) 'Body of the method 
-1
source

Source: https://habr.com/ru/post/1402399/


All Articles