xamarin.forms - xamarin 表单中的多级列表视图
问题描述
我需要在 Xamarin 表单中创建一个多级列表视图。
目前,我在菜单页面中将其用于我的单级分组
http://www.compliancestudio.io/blog/xamarin-forms-expandable-listview
我需要更新附件图像之类的内容。我尝试了一些解决方案,但都是徒劳的。
任何人都对此有任何想法。
谢谢
解决方案
Expander
你可以用of做到这一点Xamarin Community Toolkit
。
Xamarin Community Toolkit
从 NuGet安装: https ://www.nuget.org/packages/Xamarin.CommunityToolkit/
用法: xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
xml:
<ContentPage.BindingContext>
<viewmodels:RootViewModel />
</ContentPage.BindingContext>
<ContentPage.Content>
<ScrollView Margin="20">
<StackLayout BindableLayout.ItemsSource="{Binding roots}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<xct:Expander>
<xct:Expander.Header>
<Label Text="{Binding Root}"
FontAttributes="Bold"
FontSize="Large" />
</xct:Expander.Header>
<StackLayout BindableLayout.ItemsSource="{Binding Node}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<xct:Expander Padding="10">
<xct:Expander.Header>
<Label Text="{Binding Key.Node}" FontSize="Medium" />
</xct:Expander.Header>
<StackLayout BindableLayout.ItemsSource="{Binding Value}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label Text="{Binding SubRoot}" FontSize="Small" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</xct:Expander>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</xct:Expander>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ScrollView>
</ContentPage.Content>
模型:
public class Roots
{
public string Root { get; set; }
public Dictionary<Nodes, List<SubRoots>> Node { get; set; }
}
public class Nodes
{
public string Node { get; set; }
}
public class SubRoots
{
public string SubRoot { get; set; }
}
视图模型:
public class RootViewModel
{
public List<Roots> roots { get; private set; }
public RootViewModel()
{
CreateMonkeyCollection();
}
public void CreateMonkeyCollection()
{
List<SubRoots> subRoot = new List<SubRoots>() { new SubRoots() { SubRoot = "SubNode" } };
Dictionary<Nodes, List<SubRoots>> node = new Dictionary<Nodes, List<SubRoots>>();
node.Add(new Nodes() { Node="Nodo1"}, null);
node.Add(new Nodes() { Node="Nodo2"}, null);
node.Add(new Nodes() { Node="Nodo3"}, null);
node.Add(new Nodes() { Node="Nodo4"}, subRoot);
roots = new List<Roots>()
{
new Roots(){ Root="Root1", Node=node},
new Roots(){ Root="Root2", Node= null}
};
}
}
推荐阅读
- dynamics-crm - 有什么方法可以增加子网格 Dynamics CRM 365 中的保存按钮大小
- sql - 练习sql解释
- javascript - Popover关闭时Material-UI Button无法触发
- botframework - 如何使用 Rasa 通过 botframework 输出通道主动向 Skype 用户发送消息
- html - 背景太放大了
- python - 如何仅使用一个列表或元组编写代码来解决此问题
- ssh - 使用命令字符串运行 ssh 如何在幕后工作?
- c# - Unix Timestamp 有 UTC 差异
- c - 为什么 recvfrom 通过广播 IP 没有收到数据?
- c++ - 如何构造一个具有恒定引用循环的类?