VB.net 中的响应式
任何人都可以帮助我吗!
我尝试在 C# 中实现一些内容:
var keysIO = Observable.FromEvent<KeyDownEventHandler, RoutedEventArgs>(
h => new KeyDownEventHandler(h),
h => btn.KeyDown += h,
h => btn.KeyDown -= h));
How to write that in VB?
谢谢你, 右
Can anyone help me please!
I tried to implement something that in C# is:
var keysIO = Observable.FromEvent<KeyDownEventHandler, RoutedEventArgs>(
h => new KeyDownEventHandler(h),
h => btn.KeyDown += h,
h => btn.KeyDown -= h));
How to write that in VB?
Thank you,
R
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我首先让你的代码在我的机器上编译:
然后我在 Reflector 中打开它并修改为
I first got your code to compile on my machine:
Then I opened it in Reflector and modfied to
C# btn.KeyDown += h 对应于VB 中的以下内容:
同样,-= 对应于RemoveHandler。
但是,当使用不直接是通用 EventHandler(Of T) 的自定义 EventHandler 类型时,VB 编译器会出现问题。对于您的示例,我不确定自定义 KeyDownEventHandler 类型在转换参数中正在做什么。如果您不需要它,您可以使用弱类型版本:
The C# btn.KeyDown += h corresponds to the following in VB:
Similarly, -= corresponds to RemoveHandler.
However, the VB compiler has issues when using custom EventHandler types that are not directly the generic EventHandler(Of T). In the case of your sample, I"m not sure what the custom KeyDownEventHandler type is doing, in the conversion parameter. If you don't need it, you may be able to use the weakly typed version: