1
集合设置为自定义的绑定属性我有一个自定义ContentView
与定义的绑定属性:Xamarin - 在XAML
public IEnumerable<SomeItem> Items
{
get => (IEnumerable<SomeItem>)GetValue(ItemsProperty);
set => SetValue(ItemsProperty, value);
}
public static readonly BindableProperty ItemsProperty = BindableProperty.Create(
nameof(Items),
typeof(IEnumerable<SomeItem>),
typeof(MyControl),
propertyChanged: (bObj, oldValue, newValue) =>
{
}
);
我怎样才能在XAML中设置一个值吗?
我想:
<c:MyControl>
<c:MyControl.Items>
<x:Array Type="{x:Type c:SomeItem}">
<c:SomeItem />
<c:SomeItem />
<c:SomeItem />
</x:Array>
</c:MyControl.Items>
</c:MyControl>
以下编译错误
但要时时:
error : Value cannot be null.
error : Parameter name: fieldType
我做错了什么?有不同的方法吗?
我测试你的代码 - 它工作得很好!我觉得这个编译错误是由智能感知假阳性。此外,建议您更改'的IEnumerable'了'returnType'参数(在Binding.Create)为'IEnumerable的'。 –
Ada