可能重複轉換到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