我收到以下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'
附录