Custom ItemSource in XAML Not bindable

331 Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

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);