可能重复转换到VB.NET: Method group in VB.NET?奇怪的错误从C#
在阅读an answer我得到这个代码:
public static class Helper
{
public static bool GetAutoScroll(DependencyObject obj)
{
return (bool)obj.GetValue(AutoScrollProperty);
}
public static void SetAutoScroll(DependencyObject obj, bool value)
{
obj.SetValue(AutoScrollProperty, value);
}
public static readonly DependencyProperty AutoScrollProperty =
DependencyProperty.RegisterAttached("AutoScroll", typeof(bool),
typeof(Helper),
new PropertyMetadata(false, AutoScrollPropertyChanged));
private static void AutoScrollPropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
var scrollViewer = d as ScrollViewer;
if (scrollViewer != null && (bool)e.NewValue)
{
scrollViewer.ScrollToBottom();
}
}
}
由于我工作VB.NET,所以我转换它并得到:
Public NotInheritable Class Helper
Private Sub New()
End Sub
Public Shared Function GetAutoScroll(ByVal obj As DependencyObject)
As Boolean
Return CBool(obj.GetValue(AutoScrollProperty))
End Function
Public Shared Sub SetAutoScroll(ByVal obj As DependencyObject,
ByVal value As Boolean)
obj.SetValue(AutoScrollProperty, value)
End Sub
Public Shared ReadOnly AutoScrollProperty As DependencyProperty =
DependencyProperty.RegisterAttached("AutoScroll", GetType(Boolean),
GetType(Helper),
New PropertyMetadata(False, AutoScrollPropertyChanged)) // Error Here
Private Shared Sub AutoScrollPropertyChanged(ByVal d As
System.Windows.DependencyObject, ByVal e As
System.Windows.DependencyPropertyChangedEventArgs)
Dim scrollViewer = TryCast(d, ScrollViewer)
If scrollViewer IsNot Nothing AndAlso CBool(e.NewValue) Then
scrollViewer.ScrollToBottom()
End If
End Sub
End Class
但C#代码编译和工作正常,但在VB.NET代码给出了一个错误(标记代码)说:为“私人共享子AutoScrollPropertyChanged参数“E”没有指定
参数(d作为System.Windows.DependencyObject,E作为System.Windows.DependencyPropertyChangedEventArgs)”
我缺少什么?该PropertyChangedCallback
代表正是它在对象浏览器中定义的方式:
Public Delegate Sub PropertyChangedCallback(
ByVal d As System.Windows.DependencyObject, ByVal e As
System.Windows.DependencyPropertyChangedEventArgs)
参阅关于在VB方法组的其他问题。净[VB.Net中的方法组](http://stackoverflow.com/questions/12803897/method-group-in-vb-net)和[*模糊标题*实际上关于方法组](http:// stackoverflow。 com/questions/8047249/how-to-do-this-in-vb-net) – MarkJ