DataPager EventArgs
I'm using a DataPager control in my silverlight application. I have dif开发者_JS百科ferent pagers for different DataGrids and want to use the same event handler for the PageIndexChanged event for all of them. The delegate must take an EventArgs object as an argument. Can I use this object to "get back" to the control from which the event was fired?
I swear I tried this before upgrading to f# 4 and silverlight 4 and it didn't work but now it does...
http://connect.microsoft.com/VisualStudio/feedback/details/524645/f-add-event-handler-to-form-anonymous-function-is-required
The sender parameter is the reference to the object that fired the event.
So if you want to get to the DataPager
this should do it:-
DataPager dp = (DataPager)sender;
Here are my two scenarios in F#:
Scenario 1
let pageIndexChanged (args : EventHandler<EventArgs>) =
// Do something
()
pager.PageIndexChanged.AddHandler(pageIndexChanged)
Which yeilds the error
This expression was expected to have type EventHandler
but here has type
EventHandler -> unit
Scenario 2
let pageIndexChanged (args : EventArgs) =
// Do something
()
pager.PageIndexChanged.Add(pageIndexChanged)
The compiler accepts this, but I can do nothing with args
精彩评论