代码如下:
List<IrrlSysFun> datas; public CWRoleRight() { InitializeComponent(); BLL.SysFunBLL.FindAll(list => { datas = list.ToList(); LoadTree(treeView2.Items, 0); }); } private void LoadTree(ItemCollection itemCollection, int p) { var subList = datas.Where(d => d.pid == p).ToList(); foreach (var item in subList) { TreeViewItem tv = new TreeViewItem(); StackPanel sp = new StackPanel(); CheckBox cb = new CheckBox(); cb.Checked += new RoutedEventHandler(cb_Checked); cb.Content = item.nodeText; cb.Tag = tv; sp.Children.Add(cb); tv.Header = sp; itemCollection.Add(tv); tv.IsExpanded = true; LoadTree(tv.Items, item.nodeid); } }
界面效果: