F# WPF 鼠标移动参数
canvas.MouseMove.Add(move canvas update)
MouseMove.Add( p1 p2 p3)
通常我会看到这个用法和文档,两个参数—— (对象发送者,MouseEventArgs e) -- 在本示例代码中,我将其视为 move 和 canvas,摘自 F#.NET Journal 的 计算几何:快速船体。
更新有延迟吗?或将气泡信息路由到 MouseMove.Add?
我只是不明白。欢迎任何帮助。谢谢。艺术
canvas.MouseMove.Add(move canvas update)
MouseMove.Add( p1 p2 p3)
Usually I see this use and documentation, two params --
(object sender, MouseEventArgs e)
-- which I take to be move and canvas in this example code, taken from F#.NET Journal's
Computational geometry: quick hull.
Is update some delagate? or routing bubble info to MouseMove.Add?
I'm just not gettng it. Any help welcome. Thanks. Art
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
kvb 的答案给出了所有理论,所以我想我还可以添加一个代码示例。我不知道该片段的来源,所以我会根据名称进行一些猜测 - 希望它会很有用,即使它可能与原始示例不完全相同。
正如 kvb 所说,代码
move canvas update
实际上是一个函数调用,返回一个函数,然后将其作为处理程序添加到MouseMove
事件。这意味着
move
可以声明如下:注册事件处理程序时,代码
move canvas update
指定move
的前两个参数函数,以便处理程序可以访问可能在处理程序注册位置声明的canvas
值(不使用可变变量!)这也应该解释为什么事件处理程序不需要将
sender:object
作为第一个参数 - 你可以使用静态类型的方式使用部分函数应用程序将画布(即发送者)作为第一个参数传递(因此您不必强制转换对象) /code> 到Canvas
)。The answer from kvb gives all the theory, so I thought I could also add a code sample. I don't know the source of the snippet, so I'll make some guesses based on the names - hopefully it will be useful even if it may not be completely same as the original sample.
As kvb says, the code
move canvas update
is actually a function call that returns a function, which is then added as a handler to theMouseMove
event.This means that
move
could be declared as follows:When registering the event handler, the code
move canvas update
specifies the first two arguments of themove
function, so that the handler can accesscanvas
value that was probably declared in the place where the handler is registered (without the use of mutable variables!)This should also explain why the event handler does not need to take
sender:object
as the first argument - you can pass thecanvas
(which is the sender) as a first argument using partial function application in a statically typed way (so you don't have to castobject
toCanvas
).除非您有拼写错误,否则
move canvas update
是将函数move
应用于值canvas
和update,您没有显示其中任何一个;这不是传递一组 3 个独立的参数。
一般来说,F# 事件的工作方式与其他 .NET 语言中的工作方式略有不同。使用
Add
方法时,您传递的函数接受单个EventArgs
子类,而不是发送者和事件参数。如果您想从处理程序中访问发送者,请改用AddHandler
;通常这是不必要的,因为发送者只是您要添加处理程序的对象,因此您不需要从处理程序内获取对它的单独引用。Unless you've got a typo,
move canvas update
is the application of the functionmove
to the valuescanvas
andupdate
, none of which you are showing; this is not a set of 3 separate arguments being passed.In general, in F# events work slightly differently than they do in other .NET languages. When you use the
Add
method, you pass a function which takes a singleEventArgs
subclass, not the sender and the event args. If you want to access the sender from within the handler, then useAddHandler
instead; usually this isn't necessary because the sender is just the object on which you're adding the handler, so you don't need to get a separate reference to it from within the handler.