SilverlightShow: Using the TreeView control in Silverlight Comments http://www.silverlightshow.net/ Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples SilverlightShow.net http://www.rssboard.org/rss-specification Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic en-US estoychev@completit.com (Emil Stoychev) RE: Using the TreeView control in Silverlight <em>The article has been updated to the latest version of Silverlight and Visual Studio.</em> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment5147 lnikolov http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Wed, 22 Dec 2010 18:26:35 GMT RE: Using the TreeView control in Silverlight 2 Great Tutorial....Thnx a lot.... <div><br /> </div> <div>I have a situation wherein items should be dropped only on the nodes....Not above or below the nodes....when I drop an item on the node, its child should be created....</div> <div><br /> </div> <div>what should I do for that?</div> <div><br /> </div> <div>Thnx in advance....</div> <div><br /> </div> <div>Satish Chaudhary</div> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment3820 Satish Chaudhary http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Sun, 20 Jun 2010 16:26:50 GMT RE: Using the TreeView control in Silverlight 2 <p>Excellent work.This helped me to start with XML binding in treeview.</p> <p>I have a requirement like, instead of simple showing the treeview like:</p> <p></p> <p>> Announcements</p> <p>> Products</p> <p>     > Controls</p> <p>> Tools </p> <p>I wanted to show the XML nodes as it is. I mean my tree view should output like below:</p> <p> <?xml version="1.0" encoding="utf-8" ?><br /> <categories><br />   <category name="Announcements" ></category></p> <p>  <category name="Products"><br /> <br />     <category name="Controls"></category></p> <p>  </category></p> <p></categories></p> <p> Please help me in this.</p> <p></p> <p></p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment3737 Yesubabu http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Mon, 07 Jun 2010 16:59:00 GMT RE: Using the TreeView control in Silverlight 2 <p>Hi,</p> <p>this is greate article,</p> <p>I am looking for similar requirement,along with have additional requirement.</p> <p>I have xml file as </p> <p><?xml version="1.0" encoding="us-ascii"?><br /> <navtree type="Offerings Portfolio Map"><br />  <parent Name="Main Map" ><br />   <child Name="Security" ><br />    <child1 Name="Security Advisory Services" ><br />     <child2 Name="Risk Advisory Services" /><br />     <child2 Name="Compliance Services" /><br />     <br />    </child1><br />    <child1 Name="IT Security Design and Implementation"><br />     <child2 Name="Infrastructure Architecture and Engineering"  /><br />     <child2 Name="Data Protection Services" ><br />      <child3 Name="Data Protection for Backup Service" /><br />      </child2><br />     <child2 Name="Managed Messaging and Collaboration" /><br />     <child2 Name="Fraud Detection and Anti-Money Laundering" /><br />     </child1>   <br />   </child><br />   <child Name="End User Outsourcing and Support Services" ><br />    <child1 Name="End User Support Solutions" ><br />     <child2 Name="End-User Productivity Services (EUPS)" /><br />     <child2 Name="Desktop Lifecycle Management" /><br />     <br />    </child1><br />       <br />    <child1 Name="Platform as a Service Solutions" ><br />     <child2 Name="Email Management"  />       <br />    </child1><br />    <br />   </child><br />     <br />  </parent><br /> </navtree></p> <p>As soon as i load the page..parent node should be expanded..</p> <p>kindly help me how can i achive this.</p> <p> </p> <p>thanks,</p> <p>Sudha</p> <p> </p> <p> </p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment3735 sudha http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Sun, 06 Jun 2010 11:32:47 GMT RE: Using the TreeView control in Silverlight 2 This is a great Tutorial, but when if I go back to my collection and I update an element, the change is not reflected in the treeview but I can definitely see it my collection at runtime. http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment3723 Brandon http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Fri, 04 Jun 2010 07:32:19 GMT RE: Using the TreeView control in Silverlight 2 <p>Excellent work....Straight to the point. I could style and populate the treeview in our application in minutes.</p> <p>Thanks.</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment3489 Jerry http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Sat, 24 Apr 2010 14:21:30 GMT RE: Using the TreeView control in Silverlight 2 <p>Hi,</p> <p>Thank you for this tutorial.</p> <p>I try to translate this in VB.net, but I have problem.</p> <div style="border-bottom: #7f9db9 1px solid; border-left: #7f9db9 1px solid; line-height: 100% !important; background-color: white; font-family: courier new; font-size: 11px; overflow: auto; border-top: #7f9db9 1px solid; border-right: #7f9db9 1px solid;"> <table style="border-bottom: #eee 0px solid; border-right-width: 0px; background-color: #fff; margin: 2px 0px; width: 99%; border-collapse: collapse; border-top-width: 0px; border-left-width: 0px;" cellspacing="0" cellpadding="0"> <colgroup><col style="border-bottom: #f7f7f7 1px solid; padding-left: 10px; font-family: courier new; white-space: nowrap; font-size: 11px;" /></colgroup> <tbody> <tr> <td><span style="font-size: 11px;"></span><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Collections.Generic  </span></td> </tr> <tr> <td><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Linq  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Net  </span></td> </tr> <tr> <td><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Windows  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Windows.Controls  </span></td> </tr> <tr> <td><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Windows.Documents  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Windows.Input  </span></td> </tr> <tr> <td><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Windows.Media  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Windows.Media.Animation  </span></td> </tr> <tr> <td><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Windows.Shapes  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Collections.ObjectModel  </span></td> </tr> <tr> <td><span style="color: blue;">Imports</span><span style="font-size: 11px;"> System.Xml.Linq  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"> </td> </tr> <tr> <td> </td> </tr> <tr> <td style="background-color: #f7f7f7;">Partial <span style="color: blue;">Public</span><span style="font-size: 11px;"> </span><span style="color: blue;">Class</span><span style="font-size: 11px;"> MainPage  </span></td> </tr> <tr> <td>    <span style="color: blue;">Inherits</span><span style="font-size: 11px;"> UserControl  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"> </td> </tr> <tr> <td>    <span style="color: blue;">Public</span><span style="font-size: 11px;"> </span><span style="color: blue;">Sub</span><span style="font-size: 11px;"> </span><span style="color: blue;">New</span><span style="font-size: 11px;">()  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">        InitializeComponent()  </td> </tr> <tr> <td> </td> </tr> <tr> <td style="background-color: #f7f7f7;">    <span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Sub</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td> </td> </tr> <tr> <td style="background-color: #f7f7f7;">    <span style="color: blue;">Private</span><span style="font-size: 11px;"> </span><span style="color: blue;">Sub</span><span style="font-size: 11px;"> LoadData()  </span></td> </tr> <tr> <td>        <span style="color: blue;">Dim</span><span style="font-size: 11px;"> categories </span><span style="color: blue;">As</span><span style="font-size: 11px;"> </span><span style="color: blue;">New</span><span style="font-size: 11px;"> List(Of Category)()  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">        <span style="color: blue;">Dim</span><span style="font-size: 11px;"> categoriesXML </span><span style="color: blue;">As</span><span style="font-size: 11px;"> XDocument = XDocument.Load(</span><span style="color: blue;">"Chenets.xml"</span><span style="font-size: 11px;">)  </span></td> </tr> <tr> <td>        categories = <span style="color: blue;">Me</span><span style="font-size: 11px;">.GetCategories(categoriesXML.Element(</span><span style="color: blue;">"categories"</span><span style="font-size: 11px;">))  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"> </td> </tr> <tr> <td>    <span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Sub</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"> </td> </tr> <tr> <td>    <span style="color: blue;">Private</span><span style="font-size: 11px;"> </span><span style="color: blue;">Function</span><span style="font-size: 11px;"> GetCategories(</span><span style="color: blue;">ByVal</span><span style="font-size: 11px;"> element </span><span style="color: blue;">As</span><span style="font-size: 11px;"> XElement) </span><span style="color: blue;">As</span><span style="font-size: 11px;"> List(Of Category)  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"> </td> </tr> <tr> <td>        <span style="color: blue;">Return</span><span style="font-size: 11px;"> From category </span><span style="color: blue;">In</span><span style="font-size: 11px;"> element.Elements(</span><span style="color: blue;">"category"</span><span style="font-size: 11px;">) </span><span style="color: blue;">Select</span><span style="font-size: 11px;"> </span><span style="color: blue;">New</span><span style="font-size: 11px;"> Category(Name = category.Attribute(</span><span style="color: blue;">"name"</span><span style="font-size: 11px;">).Value, SubCategories = </span><span style="color: blue;">Me</span><span style="font-size: 11px;">.GetCategories(category))  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"> </td> </tr> <tr> <td> </td> </tr> <tr> <td style="background-color: #f7f7f7;"> </td> </tr> <tr> <td>    <span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Function</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td style="background-color: #f7f7f7;"><span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Class</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td> </td> </tr> <tr> <td style="background-color: #f7f7f7;"><span style="color: blue;">Public</span><span style="font-size: 11px;"> </span><span style="color: blue;">Class</span><span style="font-size: 11px;"> Category  </span></td> </tr> <tr> <td>    <span style="color: blue;">Private</span><span style="font-size: 11px;"> _Name </span><span style="color: blue;">As</span><span style="font-size: 11px;"> </span><span style="color: blue;">String</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">    <span style="color: blue;">Public</span><span style="font-size: 11px;"> </span><span style="color: blue;">Property</span><span style="font-size: 11px;"> Name() </span><span style="color: blue;">As</span><span style="font-size: 11px;"> </span><span style="color: blue;">String</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td>        <span style="color: blue;">Get</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">            <span style="color: blue;">Return</span><span style="font-size: 11px;"> _Name  </span></td> </tr> <tr> <td>        <span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Get</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">        <span style="color: blue;">Set</span><span style="font-size: 11px;">(</span><span style="color: blue;">ByVal</span><span style="font-size: 11px;"> value </span><span style="color: blue;">As</span><span style="font-size: 11px;"> </span><span style="color: blue;">String</span><span style="font-size: 11px;">)  </span></td> </tr> <tr> <td>            _Name = value  </td> </tr> <tr> <td style="background-color: #f7f7f7;">        <span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Set</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td>    <span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Property</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">    <span style="color: blue;">Private</span><span style="font-size: 11px;"> _SubCategories </span><span style="color: blue;">As</span><span style="font-size: 11px;"> List(Of Category)  </span></td> </tr> <tr> <td>    <span style="color: blue;">Public</span><span style="font-size: 11px;"> </span><span style="color: blue;">Property</span><span style="font-size: 11px;"> SubCategories() </span><span style="color: blue;">As</span><span style="font-size: 11px;"> List(Of Category)  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">        <span style="color: blue;">Get</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td>            <span style="color: blue;">Return</span><span style="font-size: 11px;"> _SubCategories  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">        <span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Get</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td>        <span style="color: blue;">Set</span><span style="font-size: 11px;">(</span><span style="color: blue;">ByVal</span><span style="font-size: 11px;"> value </span><span style="color: blue;">As</span><span style="font-size: 11px;"> List(Of Category))  </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">            _SubCategories = value  </td> </tr> <tr> <td>        <span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Set</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">    <span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Property</span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td><span style="color: blue;">End</span><span style="font-size: 11px;"> </span><span style="color: blue;">Class</span><span style="font-size: 11px;"> </span></td> </tr> </tbody> </table> </div> <p> </p> <p>One Error :</p> <p>Subcategories is on erreur (Erreur 1 Le nom 'SubCategories' n'est pas déclaré ou ne se trouve pas dans la portée )</p> <p> </p> <p>Anyome, can I Help Me?</p> <p>Thank You</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment2879 Manu http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Wed, 06 Jan 2010 16:07:03 GMT RE: Using the TreeView control in Silverlight 2 <p>hi </p> <p>I have change my <span style="font-size: 13px;">ItemContainerStyle style of Some Items in treeview on button click. please let me know how to refresh the trview componerts.</span></p> <p><span style="font-size: 13px;">thanks</span></p> <p><span style="font-size: 13px;">yogesh</span></p> <p><span style="font-size: 13px;"></span></p> <p><span style="font-size: 13px;"> <p> </p> </span></p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment2347 yogesh http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Fri, 11 Sep 2009 12:34:40 GMT RE: Using the TreeView control in Silverlight 2 thanks for this.. it really helped !! <p>i have made a style for TreeViewItem by defining some static Items.. but now i want to apply that style to Items that are databound.</p> <p>i am using the same code as you have given above (using HierarchicalDataTemplate) ... help please</p> <br /> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment1565 umer http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Thu, 14 May 2009 03:47:11 GMT RE: Using the TreeView control in Silverlight 2 How to rebind the collection when it changes? http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment1486 Al Pascual http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Fri, 17 Apr 2009 18:47:00 GMT RE: Using the TreeView control in Silverlight 2 <p>Hi, hany,</p> <p>yes, it's possible to change the direction of the text to "rtl". The easiest way is to do this:</p> <div> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: rgb(0, 0, 255);">char</span>[] c = <span style="color: rgb(0, 0, 255);">this</span>.TextBlockControl.Text.ToCharArray();</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"> Array.Reverse( c );</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: rgb(0, 0, 255);">this</span>.TextBlockControl.Text = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(0, 0, 255);">string</span>( c );</pre> </div> </div> <p>This solution was made by Tamir Khason. Now there is also an additional project in CodePlex that is related to the <a href="http://www.codeplex.com/SilverlightRTL">Silverlight 2.0 support for for Hebrew and Arabic languages</a>, again the mastermind is Tamir. And here is also <a href="http://timheuer.com/blog/archive/2007/10/26/silverlight-rtl-language-support-extension.aspx">one post</a> from Tim Heuer about the "rtl" languages, probably it will be helpful too.<br /> <br /> On the other hand if you want to change the whole design of the TreeView to right-to-left, which menas the expand-buttons to go to the right side and the alignment of the items to be right, you have to rearrange the template of the TreeView and the TreeViewItem. I don't know what exactly should be changed but I think it would be something that regards the HorizontalAlignments properties and the columns of a few grids. If you need additional help, don't hesitate to ask! ;)</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment967 Enrai http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Tue, 27 Jan 2009 07:40:54 GMT Change direction of trreview <p>how can i change direction of treeview control to "rtl" and writing arabic language element???</p> <p>there any property for that purpose???</p> <p>how??</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment944 hany http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Thu, 22 Jan 2009 04:31:24 GMT RE: Using the TreeView control in Silverlight 2 <p><strong><em>@<span id="ctl00_cphMiddle_ContentPlaceHolderContent_itemComments_dlstComments_ctl10_lblCommentAuthor">Daniel Lyle </span></em></strong><span id="ctl00_cphMiddle_ContentPlaceHolderContent_itemComments_dlstComments_ctl10_lblCommentAuthor">You can desig</span>n the business object however you like, as long as it provides you with a way to bind the TreeView to it. Instead of using an object class for the Name property you can do the following:</p> <div> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> Category<T></pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"> <span style="color: rgb(0, 0, 255);">public</span> T Name{ get; set; }</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"> ...</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"> }</pre> </div> </div> <p>This way you can template the class and pass the type of the property through the class name.</p> <p><em><strong>@ <span id="ctl00_cphMiddle_ContentPlaceHolderContent_itemComments_dlstComments_ctl12_lblCommentAuthor">AbhishekVas </span></strong></em><span id="ctl00_cphMiddle_ContentPlaceHolderContent_itemComments_dlstComments_ctl12_lblCommentAuthor">By default there is no drag and drop functionality in the TreeView control, but there should be no problem to implement such. The RadTreeView by Telerik for example allows dragging and dropping in the tree. Whne you implement the drag and drop functionality you should be able to raise an event when something is dropped. This event can be used to write the new data to the XML file. Good luck!</span></p> <p><em><strong><span>@</span><span id="ctl00_cphMiddle_ContentPlaceHolderContent_itemComments_dlstComments_ctl14_lblCommentAuthor">Zain Shaikh</span></strong></em><strong><span id="ctl00_cphMiddle_ContentPlaceHolderContent_itemComments_dlstComments_ctl14_lblCommentAuthor"> </span></strong><span>To animate the expanding  and collapsing of the nodes you should add a storyboard in the <em><strong>ViewStates </strong></em>for "<em>Expanded</em>" and "<em>Collapsed</em>" of the TreeViewItem, that will animate the container for the sub nodes. For example the Opacity of the "ItemsHost" ItemsPresenter can be easily animated, so the sub nodes will fade in and fade out.</span></p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment860 Enrai http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Sat, 20 Dec 2008 09:20:38 GMT RE: Using the TreeView control in Silverlight 2 <p><span id="1229688401759S" style="display: none"> wow, thats really goood. </span></p> <p>i applied style on the treeview but can you please tell me how to animate on collapsing and expanding...?</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment854 Zain Shaikh http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Fri, 19 Dec 2008 07:11:01 GMT Drag and drop in Treeviews <p>Dear Martin,</p> <p>I am interested to know whether we can drag and drop nodes from one tree view to another.</p> <p>My problem is that I have two  tree node which are bound to two different XML.</p> <p>now if I drag and drop item from one tree node to another, I should be able to do that with corresponding changes in XMLs.</p> <p>Regards</p> <p>Abhishek Vashistha</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment832 AbhishekVas http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Tue, 16 Dec 2008 06:45:18 GMT RE: Using the TreeView control in Silverlight 2 <p>Great tutorial.  I like the list of lists approach you suggest and the HierarchialDataTemplate.  The list of lists approach shares in the simple beauty of Lisp style lists.  The HierarchialDataTemplate reminds one of the simple beauty of the Tree controls that Java led the industry with some years ago that truly separated the model from the view.</p> <p>I did have a question -- is there a way to create a more generic list than your example recursive Category class?  I guess one could replace the Name string with an Object class (like a void pointer in C).</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment821 Daniel Lyle http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Fri, 12 Dec 2008 10:17:54 GMT RE: Using the TreeView control in Silverlight 2 <p><em><strong>@Austin</strong></em> The Category class allows me to handle unlimited levels of hierarchy, because every sub category has a collection of categories and so on and on. On the other side using the recursion with LINQ to XML there is no problem to read a XML with uknown number of levels. If you want try to add additional levels to the XML file in the source code of the example and you'll see that they are handled properly.</p> <p>About your second question: If you set the ItemsSource to an XElement or XDocument (they need a cast) you will have problems defining the bindings in the XAML. For the HierarchicalDataTemplate's source you have to set the <em>Elements("category")</em> collection and then you have to bind the value of the TextBox to the <em>Attribute("Name")</em> value. The binding syntax doesn't support brackets, so it can't be done that way. Probably workarounds can be found, but I don't think there is a need. You can just create a collection, fill it with the needed information from the XML and then define the bindings in the XAML - much easier and the code stays clear and understandable. :)</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment783 Enrai http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Tue, 02 Dec 2008 08:22:38 GMT RE: Using the TreeView control in Silverlight 2 <p>I should have asked 'Can you set the <b><i>ItemsSource</i></b> property for the TreeView to an XDocument or XElement?'</p> <p>[The reason my previous question duplicated was i submitted it, then pressed F5]</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment781 austin avrashow http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Mon, 01 Dec 2008 18:14:29 GMT RE: Using the TreeView control in Silverlight 2 <p>When you set the <b><i>ItemsSource</i></b> property to a collection, you defined a class with 2 levels of hierarchy.</p> <p>What if I wanted to bind to an XML document that has an unknown number of levels?</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment779 austin avrashow http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Mon, 01 Dec 2008 16:19:29 GMT RE: Using the TreeView control in Silverlight 2 <p>Hm, for the moment I also haven't found a way to do that, but here are my thoughts about this topic. When using databinding the <em><strong>Items </strong></em>collection of the <em><strong>TreeView </strong></em>contains the collection that I am setting as <em><strong>ItemsSource</strong></em> and there is no sign of <em><strong>TreeViewItem </strong></em>controls. On the other hand when using <em><strong>TreeViewItem </strong></em>controls the <em><strong>Items </strong></em>collection is filled with the defined controls and I can access each item in the collection and its properties. This gives me some freedom to experiment with the items and find a solution for the problem, but there are some issues that I haven't solved so far. For example this:</p> <div> <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: rgb(0, 0, 255);">public</span> Page()</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"> InitializeComponent();</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"> <span style="color: rgb(0, 0, 255);">this</span>.MyTreeView.Focus();</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"> ( ( TreeViewItem )<span style="color: rgb(0, 0, 255);">this</span>.MyTreeView.Items[ 1 ] ).IsSelected = <span style="color: rgb(0, 0, 255);">true</span>;</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"> ( ( TreeViewItem )<span style="color: rgb(0, 0, 255);">this</span>.MyTreeView.Items[ 1 ] ).Focus(); </pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"> }</pre> </div> </div> <p>I set the <em><strong>IsSelected </strong></em>proeprty of the desired item to true. When I run the application and the <em><strong>TreeView </strong></em>appears the item is selected but it's in inactive state. If you click on another item it doesn't get unselected. I've tried to focus the <em><strong>TreeView </strong></em>control and its child but it doesn't seem to work, none of them gets focused.</p> <p>Another strange thing is that when I select an item and click somewhere on the <em><strong>TreeView </strong></em>outside of the items, the first item gets selected.</p> <p>If someone have any ideas, I'll be glad to share them with me. I will continue to dig in the control, so expect more articles about it.</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment720 Enrai http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Wed, 19 Nov 2008 08:15:07 GMT RE: Using the TreeView control in Silverlight 2 <p>This is Quite Good sample</p> <p>but what i am intrested is how to show a particular category in the TreeView as Selected</p> <p>i am also using the same (treeview with databinding and hirarcheical Template) but i need to show the first item in the treeview as selected</p> http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx#comment719 Murtaza Ali http://www.silverlightshow.net/items/Using-the-TreeView-control-in-Silverlight-2.aspx Wed, 19 Nov 2008 07:01:07 GMT