silverlight - F#: Add and remove event handlers -
I'm trying to add & amp; Remove an event handler from a Silverlight Framework Element, but I can not get the syntax correct.
I have to do something like this:
click event handler = funny args - & gt; Click "Printfn!" Fe.MouseLeftButtonDown.AddHandler (clickedEventHandler) ... fe.MouseLeftButtonDown.RemoveHandler (clickedEventHandler)
What should be the correct way to do this?
As you've already mentioned, you need to make an example of a representative:
f = new MouseButtonEventHandler (funny) ch
can be used as a logic for AddHandler
or ;
RemoveHanlder
. The reason for this is that the F # function value is not actually represented as any representative type. It has its own type, which is not a representative (see also). If you look at the types of F # interactive (or VS Intelligence) types, then you can see the difference:
& gt; (Fun: OBJE) (A: Mawbutton Aventergies) - Click & gt; Print FN! ") Valve it: OBG - & gt; MouseBootNowEventsArray- & gt; Unit = (...) & gt; New MouseBuildAventHandler (Fun - oa -> Click "printfn!") Assume it: MouseButtonEventHandler = (...)
It can be misleading that F # also supports lambda function value Allows a built-in conversion to call a method for a corresponding representative type, though it only works when you give the lambda function as direct argument (I think):
fe.MouseLeftButtonDown.AddHandler (click "fun obj args -> Printfn!")
You Why is the need for delegates still in F # that the representative is a well-defined comparison semantics (they are compared to any other reference types) for the function, the F # specification does not tell when they are similar.
Comments
Post a Comment