First, sorry for my bad english. I have an EF entity that looks like:
class Item
{
public Guid Id { get; set; }
public string Title{ get; set; }
public Guid? ParentId { get; set; }
public ICollection<Item> Items { get; set; }
}
Now i want to load the data from that entity on a treeview... the best I could get is the follow xaml:
<TreeView Name="treeItems">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:Item}" ItemsSource="{Binding Items}">
<TextBlock Text="{Binding Path=Title}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
and load the data with
var itens = from it in ctx.Item select it;
treeItems.ItemsSource = itens;
This obviously displays the data on the treeview like this:
ItemA ItemA1 ItemA2 ItemA1 --repeated node ItemA2 --repeated node
How can i tweak (or rewrite) my code so the treeview displays the data in hierarchical way, without the repeated nodes?