Add ToolbarItem in Xamarin.Forms with F#

My Xamarin.Forms project contains PCL in F#. I want to add ToolbarItem on the page which navigate to some other page. How should it be done?

With my code, error comes that "The value or constructor 'this' is not defined".

This is my code:

type SomePage() = 
    inherit ContentPage()

    let _ = base.LoadFromXaml(typeof<SomePage>)

    let toolbarItem = new ToolbarItem("O", "icon", (fun() -> this.Navigation.PushAsync(OtherPage())), ToolbarItemOrder.Default, 0)
    do base.ToolbarItems.Add(toolbarItem)

Answers

  • Gigex42Gigex42 USMember ✭✭✭✭

    Within you function when the toolbaritem got activated you use this.navigation... Just delete the 'this'? I dont know what the self identifier for F# is.

  • MauliShahMauliShah INMember

    Navigation can be accessed with this or base only in F#, so I can't do it without it.

  • fbmndsfbmnds Member
      type SomePage() as this =
        ...
    
Sign In or Register to comment.