Nie mogę dowiedzieć się, dlaczego otrzymuję następujący błąd podczas ustawiania właściwości PoleSsource na sterowaniu Picker:

"Obiekt musi zaimplementować o charakterze."

xaml

Mój XAML jest następujący:

** Error: "Object must implement IConvertible." **

<Picker ItemsSource="{Binding Roles}" />

Co ciekawe, jest to, że mogę ustawić właściwość PoleSsource dla kontroli ListView bez problemów w tym samym pliku.

Różna kontrola, ale sameSsource wiązanie w tym samym pliku XAML:

** This works! **

<ListView ItemsSource="{Binding Roles}" />

Podsumowując, dlaczego otrzymuję wyjątek podczas ustawiania elementów dla wybrania, ale nie dla kontroli ListView?

Dodatek:

//--------------------------------
// Initializing viewmodel instance
//--------------------------------
var viewmodel = new Dashboard(user, _account.Query);
var page      = new DashboardPage() { BindingContext = viewmodel };

await viewmodel.LoadAsync();

.
.
.

//---------------------
// Viewmodel definition
//---------------------

type Dashboard(user:AuthenticatedUser, query:Query) =

    inherit ViewModelBase()

    let mutable name             = sprintf "%s %s" user.FirstName user.LastName
    let mutable primaryRole      = user.Role

    let mutable roles            = seq []
    let mutable role             = ""

    let mutable positions        = seq []
    let mutable position         = ""

    let mutable incidents        = seq []
    let mutable incident         = ""

    let mutable accountabilities = seq []
    let mutable accountability   = ""

    member x.Name             with get()  = name
                              and  set(v) = name        <- v
                                            base.NotifyPropertyChanged(<@ x.Name @>)

    member x.PrimaryRole      with get()  = primaryRole
                              and  set(v) = primaryRole <- v
                                            base.NotifyPropertyChanged(<@ x.PrimaryRole @>)

    member x.Roles            with get()  = roles
                              and  set(v) = roles       <- v
                                            base.NotifyPropertyChanged(<@ x.Roles @>)

    member x.Role             with get()  = role
                              and  set(v) = role        <- v
                                            base.NotifyPropertyChanged(<@ x.Role @>)

    member x.Positions        with get()  = positions
                              and  set(v) = positions   <- v
                                            base.NotifyPropertyChanged(<@ x.Positions @>)

    member x.Position         with get()  = position
                              and  set(v) = position    <- v
                                            base.NotifyPropertyChanged(<@ x.Position @>)

    member x.Incidents        with get()  = incidents
                              and  set(v) = incidents   <- v
                                            base.NotifyPropertyChanged(<@ x.Incidents @>)

    member x.Incident         with get()  = incident 
                              and  set(v) = incident    <- v
                                            base.NotifyPropertyChanged(<@ x.Incident @>)

    member x.Accountabilities with get()  = accountabilities
                              and  set(v) = accountabilities <- v
                                            base.NotifyPropertyChanged(<@ x.Accountabilities @>)

    member x.Accountability   with get()  = accountability
                              and  set(v) = accountability   <- v
                                            base.NotifyPropertyChanged(<@ x.Accountability @>)

    member x.LoadAsync() =

        async {

            do! async {
                match! user |> query.Roles with
                | Error _   -> failwith "Query for 'roles' failed"
                | Ok result -> x.Roles <- result
            }

            do! async {
                match! user |> query.Positions with
                | Error _   -> failwith "Query for 'positions' failed"
                | Ok result -> x.Positions <- result
            }

            do! async {
                match! user |> query.Incidents with
                | Error _   -> failwith "Query for 'incidents' failed"
                | Ok result -> x.Incidents <- result
            }

            do! async {
                match! user |> query.Accountabilities with
                | Error _   -> failwith "Query for 'accountabilities' failed"
                | Ok result -> x.Accountabilities <- result
            }

        } |> Async.StartAsTask
0
Scott Nimrod 20 marzec 2020, 14:03

1 odpowiedź

Najlepsza odpowiedź

Miałem użyć obserwableCollection zamiast IEnumerabled (I.E. SEQ).

Uwaga: Nie jestem pewien, dlaczego Listview pracował bez tego.

let mutable roles = ObservableCollection<string>() // Updated
...

member x.LoadAsync() =

    async {

        do! async {
            match! user |> query.Roles with
            | Error _   -> failwith "Query for 'roles' failed"
            | Ok result -> x.Roles <- ObservableCollection<string>(result) // Updated
        }
0
Scott Nimrod 20 marzec 2020, 12:54