我在 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才能使用这个,以前的版本还不支持这个。
关于c# - 如何 : Convert anonymous method to VB. NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9784285/