c# - WPF: Add multiple level with different types items to TreeView -


i have class (classa) contains 2 different types of lists, list of classbtypes , list of classc. classbtypes has own list of classb.

i want achieve below structure treeview

-- classaname    -- -- classbtype1name   -- -- -- classb1name   -- -- -- classb2name      -- -- classbtype2name   -- -- -- classb1name   -- -- -- classb2name   -- -- classc1name   -- -- classc2name 

i managed tree draw classa , classb, couldn't figure out how add classc tree resources.
please check below source code.

test.xaml.cs

public partial class test : window {         initializecomponent();     var = new list<classa>{new classa(), new classa()};     treeview.itemssource = a; } 

c# classes:

public class classa{         // initiate obj         public string name {get; set;}          public list<classbtypes> btypes {get; set;}          public list<classc> c {get; set;}     }     public class classbtypes{         public string name {get; set;}         public list<classb> b {get; set;}    }     public class classb{         public string name {get; set;}     }      public class classc{        public string name {get; set;}    }   

xaml code:

<window.resources>     <datatemplate x:key="akey">         <textblock text="{binding name}"></textblock>     </datatemplate>     <hierarchicaldatatemplate x:key="bkey"                itemssource="{binding b}"                itemtemplate="{staticresource akey}">         <textblock text="{binding name}" />     </hierarchicaldatatemplate>     <hierarchicaldatatemplate x:key="btypekey"                itemssource="{binding btypes}"                itemtemplate="{staticresource bkey}">         <textblock text="{binding name}" />     </hierarchicaldatatemplate> </window.resources>    .....      <grid>    <treeview name="treeview" itemtemplate="{staticresource btypekey}" /> </grid> 

how add classc list classa obj, i've added below code <window.resources> how can added treeview resources.

<hierarchicaldatatemplate x:key="btypekey"          itemssource="{binding btypes}"          itemtemplate="{staticresource bkey}">     <textblock text="{binding name}" /> </hierarchicaldatatemplate> 

i fixed combine 2 types of lists compositecollection.
check answer more details.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -