Silverlight vs WPF - Treeview with HierarchialDataTemplate -
so, following easy enough in wpf, how in silverlight?
please note trick here display both groups, , entries on same level. additonally dont know how deep entries nested, might on first, or nth level. hard in silverlight because lack datatype="{x:type local:group}" property in h.datatemplate (or datatemplate). building own custom datatempalteselector didnt work, because hierarchial itemssource gets lost. (which gave me new idea investigate shortly)
example:
group1 --entry --entry group2 --group4 ----group1 ------entry ------entry ----entry ----entry --entry --entry group3 --entry --entry
your classes:
public class entry { public int key { get; set; } public string name { get; set; } } public class group { public int key { get; set; } public string name { get; set; } public ilist<group> subgroups { get; set; } public ilist<entry> entries { get; set; } }
your xaml:
<treeview name="groupview" grid.row="0" grid.column="0" itemssource="{binding}"> <treeview.resources> <hierarchicaldatatemplate datatype="{x:type local:group}" itemssource={binding items}"> <textblock text="{binding path=name}" /> </hierarchicaldatatemplate> <datatemplate datatype="{x:type local:entry}" > <textblock text="{binding path=name}" /> </datatemplate> </treeview.resources> </treeview>
the treeview control silverlight toolkit supports hierarchical data templates.
check out article sample usage, looks identical me wpf built in one.
you can download silverlight toolkit here.
Comments
Post a Comment