简体   繁体   中英

F# EventHandler Implementation

I have a RangeSliderControl from the following repository:

https://github.com/halkar/xamarin-range-slider

I am having trouble with implementing a method which will handle the slider being moved:

In Swift, we can simply do this:

priceSlider.addTarget(self, action: #selector(updatePrice),
                          for: .valueChanged)

and then we would have the updatePrice method:

func updatePrice() {
    //code
}

I don't understand how to do this in F#. I found the addTarget method, however, it has the following signature and I am not sure how to carry out the conversion. I assume the second argument would simply be UIControlEvent.ValueChanged , however what would the syntax for the EventHandler be?

在此处输入图片说明

EDIT:

在此处输入图片说明

我相信事件处理程序将按以下方式注册:

priceSlider.AddTarget(EventHandler (fun sender event -> updatePrice(...)), UIControlEvent.ValueChanged)

The EventHandler should be something like:

fun evArgs -> .... your event handling code ....

and so the AddTarget call should be:

AddTarget (fun evArgs -> .... your event handling code ...), UIControlEvent.ValueChanged

source: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/members/events

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM