gpt4 book ai didi

c# - 从 C# 转换为 VB.NET 的代码中出现奇怪错误

转载 作者:行者123 更新时间:2023-11-30 19:06:15 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate: Method group in VB.NET?

阅读时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 中,代码给出错误(在代码中标记)说:

Argument not specified for parameter 'e' of 'Private Shared Sub AutoScrollPropertyChanged(d As System.Windows.DependencyObject, e As System.Windows.DependencyPropertyChangedEventArgs)'

Eenter image description here

我错过了什么? PropertyChangedCallback 委托(delegate)正是它在对象浏览器中定义的方式:

Public Delegate Sub PropertyChangedCallback(
ByVal d As System.Windows.DependencyObject, ByVal e As
System.Windows.DependencyPropertyChangedEventArgs)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com