【发布时间】:2017-08-16 23:30:15
【问题描述】:
我有一个自定义的ContentView,其中定义了可绑定属性:
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
我做错了什么?有什么不同的方法吗?
【问题讨论】:
-
我测试了你的代码 - 它工作正常!我认为这个编译错误是来自智能感知的误报。此外,建议您将
returnType参数(在 Binding.Create 中)从IEnumerable<CarouselTabbedItem>更改为IEnumerable<SomeItem>。
标签: xaml xamarin xamarin.forms