一,项目需求。
在一些项目中,需要用到树形控件。一些项目中有商品的分类选择,有商品是属于电子产品,有些商品则属于服装,这时候就可以用到树形控件(Tree View),如下图:
二,开始构建Tree View
1. xaml页面中声明一个Tree View:
2. xaml.cs页面中:
(1)构建实体
/// <summary>
/// 1、构建实体
/// </summary>
public class ProjectModule
{
public int ID { get; set; }
public string menuName { get; set; }
public string menucode { get; set; }
public string menuicon { get; set; }
public int ParentId { get; set; }
public List<ProjectModule> Nodes { get; set; }
public ProjectModule()
{
//创建当前节点
this.Nodes = new List<ProjectModule>();
//当前父级ID为零
this.ParentId = 0;//主节点的父id默认为0
}
}
(2)绑定数据