xaml - 列表包括另一个列表 xamarin 表单
解决方案
您可以尝试使用带有嵌套 CollectionView 或 ListView 的可绑定布局,这将允许您使用列表列表进行数据绑定。
它可能看起来像这样;
C#
public class MyNestedListItem {
public MyNestedListItem(string myTest) {
MyText = myText;
}
public string MyText { get; set; }
}
public class MyList {
public MyList(string listName, list<MyNestedListItem> myNestedList) {
ListName = listName;
MyNestedList = myNestedList;
}
public string ListName { get; set; }
public List<MyNestedListItem> MyNestedList { get; set; }
}
public class MyViewModel {
public ObservableCollection<MyList> MyList { get; set }
public MyViewModel() {
var nestedListA = new List<MyNestedListItem>
{
new MyNestedListItem("A1");
new MyNestedListItem("A2");
new MyNestedListItem("A3");
}
var nestedListB = new ...;
MyList = new ObservableCollection<MyList> {
new MyList("List A", nestedListA);
new MyList("List B", nestedListB);
}
}
}
XAML
<StackLayout Orientation="Horizontal"
VerticalOptions="Start"
HorizontalOptions="Center"
BindableLayout.ItemsSource="{Binding MyList}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame WidthRequest="75"
HeightRequest="25"
CornerRadius="25"
Padding="0"
HasShadow="True">
<Label Text="{Binding ListName }"
<CollectionView ItemsSource="{Binding MyNestedList }"
VerticalOptions="Center"
HorizontalOptions="Center">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
< ..... your layout stuff here />
</StackLayout>
</DataTemplate>
</CollectionView>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
这可能是实现嵌套列表的良好起点
推荐阅读
- javascript - 将圆形边框转换为可点击功能
- c# - 防止在 Asp.net Web 表单中上传文件
- angular - 动态 href 调用标签 ionic 3 app
- c# - how to show number of users by age group in chart control in Asp.net MVC
- ios - iOS中导航控制器的点击手势(MMDrawerController)
- javascript - JavaScript 在迭代数组时等待后端响应
- python - 域名下划线问题
- apache-spark - 火花驱动程序如何处理大于其内存的数据?想想集群上的 TB 数据,我们通过键或收集进行减少
- amazon-s3 - AWS 编码使用负载均衡器部署多个应用程序
- apache-spark - 使用 spark sql 时如何在程序中获取当前正在运行的作业信息