0

I created a custom control which should have an ItemSource. So I added a BindableProperty and tried to bind it, but I always receive the following error:

"Position 18:46. No property, bindable property, or event found for 'ItemsSource', or mismatching type between value and property. "

The Binding: <controls:SeatsView x:Name="Control" ItemSource="{Binding Rows}">

Property:

public IEnumerable ItemSource
{
    get => (IEnumerable)GetValue(ItemSourceProperty);
    set => SetValue(ItemSourceProperty, value);
}
public BindableProperty ItemSourceProperty =
        BindableProperty.Create(nameof(ItemSource), typeof(IEnumerable), typeof(SeatsView), defaultValue: null, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnItemSourceChanged);

If I bind it in code behing like Control.ItemsSource = v.Rows; it works fine...

I also tried to add a typeconverter but it doesn't work either

Any ideas

Nehl-IT
  • 523
  • 3
  • 15
  • 1
    There is an Spelling error with ItemsSource and ItemSource so that can be an issue. – Nikhil Oct 29 '19 at 14:12
  • Hi, About usage of [Bindable Properties](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/xaml/bindable-properties) , you can refer to this document . And Uraitz's answer you can have a try . – Junior Jiang Oct 30 '19 at 03:06

1 Answers1

0

Bindable property should be static and readonly

    public static readonly BindableProperty ItemSourceProperty =
    BindableProperty.Create(nameof(ItemSource), typeof(IEnumerable), typeof(SeatsView), defaultValue: null, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnItemSourceChanged);
Uraitz
  • 476
  • 4
  • 12