我想在Treeview中显示数据:(* 1)
- There are 2 tickets
-- Opening problem category with ID 5685
-- Closing problem category with ID 5687
- There are 3 projects
-- WPF project with ID 1234
-- C# project with ID 12345
-- ASP.NET project with ID 12
Tickets
,Projects
类继承自EntityBase
类
public class EntityBase
{
public int EntityID { get; set; }
public static EntityCollection entityCollection { get; set; }
public EntityBase()
{
entityCollection = new EntityCollection();
}
}
EntityCollection具有私有List<EntityBase>
数据。
为了制作项目或门票的父节点,我创建了TreeViewParentNode
class
public class TreeViewParentNode
{
public string ParentName { get; set; }
public List<EntityBase> ParentItems;
public int ParentCount;
public TreeViewParentNode(string ParentName)
{
ParentCount = 0;
this.ParentName = ParentName;
ParentItems = new List<EntityBase>();
}
}
我创建了一个集合来显示Treeview
ObservableCollection<TreeViewParentNode>
中的数据
Window的构造函数:
public ReminderExtendedWindow()
{
InitializeComponent();
this.ResizeMode = ResizeMode.NoResize;
List<TreeViewParentNode> Nodes = new List<TreeViewParentNode>();
foreach (EntityBase EntityItem in EntityBase.entityCollection)
{
TreeViewParentNode findnode = Nodes.Find(
delegate(TreeViewParentNode node)
{
return node.ParentName == EntityItem.GetType().Name;
}
);
if (findnode == null)
{
TreeViewParentNode NewParentNode = new TreeViewParentNode(EntityItem.GetType().Name);
NewParentNode.ParentItems.Add(EntityItem);
NewParentNode.ParentCount++;
Nodes.Add(NewParentNode);
}
else
{
findnode.ParentItems.Add(EntityItem);
findnode.ParentCount++;
}
}
Coll = new ObservableCollection<TreeViewParentNode>(Nodes);
DataContext = this;
}
Treeview XAML 代码
<TreeView Height="500" Width="375" Background="Transparent" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,50,0,0"
BorderThickness="0,0,0,0" x:Name="EntityTree" ItemsSource="{Binding Coll}">
如何显示上面显示的数据(* 1)?