Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

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>)>]

    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


Sign In or Register to comment.