Listview分组错误:'System.Object []'

时间:2018-05-14 07:14:37

标签: xamarin.forms f#

我收到以下Listview分组错误:

  

绑定:'System.Object []'找不到'Profile'属性,目标属性:'Xamarin.Forms.Label.Text'

我正在尝试将以下类用于ListView grouping

type RecentLinksAdapter(profileSeed, linksSeed) =
    let mutable profile =     profileSeed
    let mutable recentLinks = linksSeed

    member x.Profile 
        with get()=       profile
        and  set(value) = profile <- value

    member x.RecentLinks
        with get() =      recentLinks
        and  set(value) = recentLinks <- value

然后我有一个viewmodel引用上面的类型作为ObservableCollection:

type ViewModel(dependencies) =

    inherit ViewModelBase()

    ...

    let mutable subscritions = ObservableCollection<RecentLinksAdapter>()

    member x.Subscriptions
             with get() =      subscritions
             and  set(value) = subscritions <- value
                               base.NotifyPropertyChanged(<@ x.Subscriptions @>)

member x.Init() =

    let setSubscriptions (result:ProviderRequest list) =
        let adapter = result |> List.map (fun s -> RecentLinksAdapter(s.Profile, s.RecentLinks))
        x.Subscriptions <- ObservableCollection<RecentLinksAdapter>(adapter)

    userId
     |> query.Subscriptions
     |> function
        | Result.Ok    result -> setSubscriptions result
        | Result.Error msg    -> ...

这是我正在尝试将分组应用到的ListView:

<ListView ItemsSource="{Binding Subscriptions}"
                  IsGroupingEnabled="True">

            <ListView.GroupHeaderTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Label Text="{Binding Profile, Converter={StaticResource NameConverter}}" 
                               FontSize="Micro" />
                    </ViewCell>
                </DataTemplate>
            </ListView.GroupHeaderTemplate>

            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                       <Label Style="{StaticResource LinkStyle}" Text="{Binding Title}" />
                    </ViewCell>

                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

以下是三个绑定错误:

[0:] Binding: 'Profile' property not found on 'System.Object[]', target property: 'Xamarin.Forms.Label.Text'
[0:] Binding: 'Profile' property not found on 'System.Object[]', target property: 'Xamarin.Forms.Label.Text'
[0:] Binding: 'Profile' property not found on 'System.Object[]', target property: 'Xamarin.Forms.Label.Text'

附录

  1. 值转换器 NameConverter 永远不会被执行。

  2. 用户界面在订阅中的每个订阅项目中显示三个空白字段。

  3. Subscriptions is initialized with three items

    enter image description here

    以下是 RecentLinks 引用的链接定义:

    [<CLIMutable>]
    type Link = { 
        ..
        Title:         string
        ..
    }
    

    以下是个人资料定义:

    [<CLIMutable>]
    type ProfileRequest = {
        ...
        FirstName:  string
        LastName:   string
        ...
    }
    

0 个答案:

没有答案