XAML 中的自定义 ItemSource 不可绑定
Custom ItemSource in XAML Not bindable
我创建了一个应该有 ItemSource 的自定义控件。
所以我添加了一个 Bindable属性 并尝试绑定它,但我总是收到以下错误:
"Position 18:46. No property, bindable property, or event found for 'ItemsSource', or mismatching type between value and property. "
绑定:<controls:SeatsView x:Name="Control" ItemSource="{Binding Rows}">
属性:
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);
如果我在代码中绑定它,就像 Control.ItemsSource = v.Rows;
它工作正常...
我也尝试添加类型转换器,但它也不起作用
任何想法
Bindable 属性 应该是 static 和 readonly
public static readonly BindableProperty ItemSourceProperty =
BindableProperty.Create(nameof(ItemSource), typeof(IEnumerable), typeof(SeatsView), defaultValue: null, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnItemSourceChanged);
我创建了一个应该有 ItemSource 的自定义控件。 所以我添加了一个 Bindable属性 并尝试绑定它,但我总是收到以下错误:
"Position 18:46. No property, bindable property, or event found for 'ItemsSource', or mismatching type between value and property. "
绑定:<controls:SeatsView x:Name="Control" ItemSource="{Binding Rows}">
属性:
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);
如果我在代码中绑定它,就像 Control.ItemsSource = v.Rows;
它工作正常...
我也尝试添加类型转换器,但它也不起作用
任何想法
Bindable 属性 应该是 static 和 readonly
public static readonly BindableProperty ItemSourceProperty =
BindableProperty.Create(nameof(ItemSource), typeof(IEnumerable), typeof(SeatsView), defaultValue: null, defaultBindingMode: BindingMode.TwoWay, propertyChanged: OnItemSourceChanged);