Search code examples
xamarin-zebblezebble

How to show items in Zebble ItemPicker?


I set the control.datasource of formfield to a object and then fill it in code behind, but when I tap on it on run time it just show class name of the object insted of value which I set.

I think I have already followed the documentation here: Zebble ItemPicker-Class

my code is :

 mypage.zbl

<FormField z-of="ItemPicker" Id="Type" LabelText="Type" 
  Control.AllowNull="true"
  Control.DataSource="@(Database.GetList&lt;ContactType&gt;())" />

myentity

public partial class Contact : GuidEntity
{
   public string Name { get; set; }

}

here is a screen shot of my application


Solution

  • When you set the data source of an ItemPicker to some list of objects, the ToString() of that object will be displayed for each item.

    The easiest fix for your problem is to add a ToString() method to your source class:

    public partial class Contact : GuidEntity
    {
       public string Name { get; set; }
    
       public override string ToString() => this.Name;
    }