如何:将匿名方法转换为VB.NET
本文关键字:转换 VB NET 方法 如何 | 更新日期: 2023-09-27 18:28:17
我在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);
}
};
我在将匿名方法转换为VB.NET.时遇到了一些问题
我的变体是
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
我添加Function As Boolean
是因为没有返回类型不是函数,但制作"Sub"我不知道如何。。。
一些建议?
匿名方法的语法如下:
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
然而,您需要VB10才能使用此功能,以前的版本还不支持此功能。
使其成为SUB.
Public SUB <method name>(<parameters>)
'Body of the method