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.

Unable to observe page navigation using F# Async support in Xamarin.Forms

I'm unable to observe page navigation.

Command:

member x.AddBankcard =    DelegateCommand( (fun _ -> async { do! navigate() 
                                                           } |> Async.RunSynchronously 
                                                             |> ignore ) ,
                                            fun _ -> true) :> ICommand

Publish navigation request:

let navigate() =

    account 
     |> PageRequest.AddBankcard 
     |> broadcastToAsync pageRequesthandlers     

Notify subscribers of request:

let broadcastToAsync<'a> (handlers:(list<'a -> Async<unit>>)) (msg:'a) : Async<unit> =

    async { handlers |> List.map (fun handle -> async { do! handle msg }) |> ignore }

Handle navigation:

let handle = function
    | PageRequest.AddBankcard _ ->
        page |> function 
        | :? UI.AddBankcard as pageRequest ->
            ...
            async { do! navigationPage.PushAsync(pageRequest) |> Async.AwaitTask }

        | _ -> async { () }
    | _ -> async { () }

Note:

  1. No page navigation occurs.

  2. I don't receive any exceptions.

  3. I don't see any clues in the output window

  4. My hunch is I'm not using async correctly.

    async { do! navigationPage.PushAsync(pageRequest) |> Async.AwaitTask }

UPDATED:

I also tried the following:

let navigationPage = (app:?>Application).MainPage:?>NavigationPage

let navigate () = async  {
    do! navigationPage.PushAsync(pageRequest) |> awaitTask
}

navigate() |> Async.RunSynchronously |> ignore

Here's the source code

Answers

Sign In or Register to comment.