【发布时间】:2020-07-12 18:02:56
【问题描述】:
我在网上找到了非常有前途的代码,我想尝试一下。
由于我的项目是用VB.net 编写的,而有问题的代码在C# 中,我开始将我需要的点点滴滴翻译成VB.net。
我已经完成了翻译,但我无法弄清楚一行特定的代码究竟做了什么以及如何将其翻译成 VB.net。
而且我不知道如何用 google 搜索来自己找到答案。
那么也许您可以对 C# 的奥秘有所了解?
这是 C# 源代码(精简到相关位):
public class TestClass
{
private ListView listView;
public TestClass(ListView input)
{
this.listView = input;
this.listView.Loaded += new RoutedEventHandler(ListViewLoaded);
this.listView.Unloaded += new RoutedEventHandler(ListViewUnloaded);
}
public static readonly DependencyProperty EnabledProperty = DependencyProperty.RegisterAttached(
"Enabled",
typeof(bool),
typeof(TestClass),
new FrameworkPropertyMetadata(new PropertyChangedCallback(OnEnabledChanged)));
private static void OnEnabledChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
ListView input = obj as ListView;
new TestClass(input); // <== this is the mystic line
}
}
我正在为静态过程OnEnabledChanged 中的最后一行代码而苦苦挣扎。看起来这个类的构造函数被调用了,但是结果没有被赋值给任何东西。
将其转换为 VB.net 为 New TestClass(input) 会导致语法错误。
我在互联网上尝试了一些自动翻译,但它们只返回New TestClass(input),所以它们和我一样聪明(或不知道)。
那么你能告诉我这行代码是做什么的,以便我可以将其转换为有效的 VB.net 吗?
【问题讨论】:
-
object input = ...这不可能。但这很关键。请显示整行。 -
没什么大不了的。更改了描述中的示例代码。
-
这让我想知道:你的代码有终结器吗?
-
没有终结器,只有构造函数。
-
好的,那么这些事件永远不会发布
this.listView.Loaded +=....