BindablePicker from FreashEssentials is not working anymore!?

RicardoSRicardoS ✭✭✭ESMember ✭✭✭
edited March 20 in Xamarin.Forms

Oh boy, this is gonna take a long time...

So, we're using bindable pickers to select options in a questionnaire. These options are loaded form a list, which the app downloads from an specific url.
And the amount of questions per list and list themselves changes, so the creation of pickers must be dynamic (i.e.: programmatically, c# code). We'll show you an example:

    static BindablePicker SetResPicker (List<Option> options) {
        BindablePicker bin = new BindablePicker {
            ItemsSource = options, DisplayProperty = "value", TextColor = ColorPicker (1),
            HorizontalOptions = FILLNEXP, VerticalOptions = CENTERNEXP
        };
        return bin;
    }

where the "value" property is a string, mainly a "YES" or a "NO", but sometimes three or more options are available ("Great", "Good", "Bad", "Unknown"; for example).

But, suddenly, when the app starts loading a bunch of questions (default, as this is a test), it ends at the "MainActivity" of the Android part with this message:

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.InvalidCastException: Specified cast is not valid.
[MonoDroid] at FreshEssentials.Droid.BindablePickerRendererDroid.OnElementChanged

Yes, we are starting our tests in Android.
We have confirmed that the List of Options is correct (all strings, no null values, etc), so we tried a Picker item from Xamarin.Forms. This is the result:

    static Picker SetBindPicker (List< Option > options) {
        Picker picker = new Picker {
            Title = "Options", TextColor = ColorPicker (1),
            HorizontalOptions = FILLNEXP, VerticalOptions = CENTERNEXP
        };
        picker.SetBinding (Picker.ItemsSourceProperty, "options");
        picker.ItemDisplayBinding = new Binding ("value");
        return picker;
    }

but the selector is empty, only a "0" is shown.
Is anything wrong with our "SetBindPicker" code?
Does it lack something?
Are there other options in case of not finding a solution?

Thank you for your time.

Answers

  • RicardoSRicardoS ✭✭✭ ESMember ✭✭✭

    I almost forgot to include the "Option" class, in case it helps with the issue:

    namespace Lib {
    public class Option {
    public int id { get; set; }
    public string value { get; set; }

        public Option () { }
    
        public Option (int id, string value) {
            this.id = id;
            this. value = value;
        }
    }
    

    }

  • jezhjezh Xamurai Member, Xamarin Team Xamurai

    Could you please post a basic demo so that we can test with it ?

  • RicardoSRicardoS ✭✭✭ ESMember ✭✭✭

    Sure thing.

    "Option" class:

    `namespace Lib {
    public class Option {
    public int id { get; set; }
    public string value { get; set; }

        public Option () { }
    
        public Option (int id, string value) {
            this.id = id;
            this. value = value;
        }
    }
    

    }`

    "MainPage.xaml.cs":

    `using System.Collections.Generic;
    using DrawLib;
    using FreshEssentials;
    using Xamarin.Forms;

    namespace trialtry {
    public partial class MainPage : ContentPage {
    public MainPage () {
    InitializeComponent ();
    List options = new List ();
    options.Add (new Option (6, "YES"));
    options.Add (new Option (7, "NO"));
    box.Children.Add (SetBindPicker (options));
    box.Children.Add (SetBindPicker (options));
    box.Children.Add (SetBindPicker (options));
    }

        static BindablePicker SetResPicker (List<Option> options) {
                    BindablePicker bin = new BindablePicker {
                        ItemsSource = options, DisplayProperty = "value", TextColor = Color.FromHex("#DEDEDE"),
                        HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand
                    };
                    return bin;
            }
    
            static Picker SetBindPicker (List<Option> options) {
            Picker picker = new Picker {
                TextColor = Color.FromHex ("#DEDEDE"),
                HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand
            };
            picker.SetBinding (Picker.ItemsSourceProperty, "options");
            picker.ItemDisplayBinding = new Binding ("value");
            return picker;
        }
    }
    

    }`

    "MainPage.xaml":

    <?xml version="1.0" encoding="utf-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:trialtry" x:Class="trialtry.MainPage"> <StackLayout x:Name="box"/> </ContentPage>

    I hope this is everything you need.
    Regards

Sign In or Register to comment.