如何解决Xamarin XAML,如何将元组列表绑定到可绑定布局
我有一个List itemsources,我想将其绑定到可绑定的布局,其语法是什么?
<StackLayout BindableLayout.ItemsSource="{Binding itemsources}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout Spacing="4">
<Label Text="{Binding a???}" />
<Label Text= "{Binding b????}"/>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
解决方法
如果您查看Tuple的文档,就会发现属性已命名
- Item1
- Item2
所以您的XAML是
<Label Text="{Binding Item1}" />
<Label Text="{Binding Item2}" />
,
您不应使用 ValueTuple ,因为它是一个结构,因此无法绑定。您应该使用常规的元组,它是引用类型。
更改:
List<(string a,string b)>
至:
List<Tuple<string,string>>
您的绑定应如下所示:
<StackLayout Spacing="4">
<Label Text="{Binding Item1}" />
<Label Text="{Binding Item2}" />
</StackLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。