【问题标题】:Xaml Parse Exception - type mismatch between "Xamarin.Forms.Binding" and "System.Collections.Generic.IEnumerable`1[System.String]"Xaml Parse 异常-“Xamarin.Forms.Binding”和“System.Collections.Generic.IEnumerable`1[System.String]”之间的类型不匹配
【发布时间】:2017-08-27 12:57:15
【问题描述】:

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

这是我的班级:

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 属性。

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

【问题讨论】:

    标签: c# xaml xamarin binding xamarin.forms


    【解决方案1】:

    可绑定属性需要遵守一套命名约定。例如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}"
    

    【讨论】:

    • 谢谢。它现在不会抛出错误。但是,该集合没有被调用。 TabItemSource 始终返回 null。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 2013-09-26
    • 1970-01-01
    • 2012-07-24
    相关资源
    最近更新 更多