Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Picker ItemsSource not binding

$
0
0

I'm attempting to bind a Picker to an ObservableCollection and nothing displays. I have set up a second property, CategoryCount, to return the count of the collection, which correctly shows 2.

    <StackLayout Spacing="20" Padding="15">
        <Label Text="Category" FontSize="Medium" />
        <Picker ItemsSource="{Binding CategoryList}"  ItemDisplayBinding="{Binding Name}" SelectedItem="{Binding Item.Category}" />
        <Label Text="Category Count"/>
        <Label Text="{Binding CategoryCount}"/>
    </StackLayout>


public class ItemDetailViewModel : BaseViewModel
 {
    public ObservableCollection<Category> CategoryList;
    public string CategoryCount
    {
        get
        {
            return CategoryList.Count.ToString();
        }
    }
    public LedgerEntry Item { get; set; }

    public ItemDetailViewModel(LedgerEntry item)
    {
        Item = item;
        CategoryList = new ObservableCollection<Category>()
        {
            new Category(){Id = 1, Name="test"},
            new Category(){Id = 2, Name = "hallo"}
        };
        OnPropertyChanged("CategoryList");
    }
}


public class Category
  {
     public int Id { get; set; }
     public string Name { get; set; }
  }

I've tried changing it to a List of strings with proper values, and could not get that working either. Any thoughts on why I'm having this issue?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>