Xaml Parse Exception - “Xamarin.Forms.Binding”和“System.Collections.Generic.IEnumerable`1 [System.String]”之间的类型不匹配

时间:2017-04-02 17:38:10

标签: c# xaml xamarin binding xamarin.forms

我正在尝试在xaml中的内容视图类中设置/绑定list属性。

这是我的班级:

public class Myclass:ContentView
{
public static readonly BindableProperty TabItemSourceProperty = BindableProperty.Create(
            "TabIndicatorItemSource",
            typeof(IEnumerable<string>),
            typeof(Myclass)
        );

public IEnumerable<string> TabIndicatorItemSource { 
get
{
    return (IEnumerable<string>)GetValue(TabItemSourceProperty);
}
set
{
    SetValue(TabItemSourceProperty, value);
}
}}

,这是我在ExampleClass.xaml.cs中的Xaml

local:Myclass x:Name="myCarouselView" TabTextSizeTabIndicatorItemSource ="{Binding tabListSource}"

tabListSource是ExampleClass.cs中的List属性。

但是我遇到了这种类型不匹配的错误。我哪里错了?

1 个答案:

答案 0 :(得分:0)

Bindable Properties需要遵守设定的命名约定。例如TabItemSourceProperty与TabItemSource

有关
public class Myclass: ContentView
{
    public static readonly BindableProperty TabItemSourceProperty = BindableProperty.Create(
            "TabItemSource",
            typeof(IEnumerable<string>),
            typeof(Myclass)
        );

    public IEnumerable<string> TabItemSource { 
        get
        {
             return (IEnumerable<string>)GetValue(TabItemSourceProperty);
        }
        set
        {
            SetValue(TabItemSourceProperty, value);
        }
    }}

local:Myclass x:Name="myCarouselView" TabItemSource="{Binding tabListSource}"