How to write a custom renderer in iOS/Android, using F#?

snuffsnuff RUMember
edited October 2016 in Xamarin.Forms

Hello all.

I'm writing an application using F# and Xamarin.Forms. I want to get touch location on AbsoluteLayout.
Smart guys say that one should use custom renderers to achieve this.
Here is C# version in Cyril's answer.

Here is my F# implementation of his approach:

...
open Xamarin.Forms.Platform.iOS
open UIKit
open GameBoardLayout

type GameBoardLayoutRenderer () =
    inherit VisualElementRenderer<Layout> ()

    [<assembly: Xamarin.Forms.ExportRendererAttribute (typeof<GameBoardLayout>, typeof<GameBoardLayoutRenderer>)>]
    do
        ()

    override this.TouchesBegan (touches, e) =

        base.TouchesBegan (touches, e)

        let gbl = this.Element :?> GameBoardLayout

        let touch = touches.AnyObject :?> UITouch
        let pos = touch.LocationInView( touch.View )

        gbl.GetTouchedColumn(float pos.X, float pos.Y)

        ()


But it doesn't work and also there is a warning on do () section saying:
Attributes have been ignored in this construct

Please, help :)

Best Answer

Answers

Sign In or Register to comment.