Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The "answer" above in my view does not answer the actual question, and in fact the original question indicates that the question author already had a very efficient solution to the problem. However, the "answer" provided simply shows how to attach a sub-object to a TreeViewItem and how to subsequently render it using a custom method. While this is useful, this answer does not address the actual nature of the original question.</p> <p>There are many scenarios where a TreeViewItem needs to have an external object attached which does not belong in the TreeViewItem's Items list. This facilitates access to the attached external object for application-specific purposes when the user selects the TreeViewItem from the TreeView. This concept is entirely different from the idea of adding sub-objects to a TreeViewItem.</p> <p>An alternate method of solving this problem, as opposed to the solution originally implemented by the question author, is to subclass the TreeViewItem class and add custom information, such as an attached object. This principle is illustrated in the article <a href="http://msdn.microsoft.com/en-us/library/1330h6a4.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/1330h6a4.aspx</a>. After implementing this custom TreeViewItem subclass, this subclass may be added to the Items list of either a TreeView or a TreeViewItem. When the user selects the item from the TreeView, the object returned from the selection will be the custom subclass, which will contain whatever custom information the subclass has defined.</p> <p>An additional advantage of using a custom TreeViewItem subclass instead of a TreeViewItem is that custom behaviors can be implemented by the subclass. For example, to display a custom tooltip when the user hovers the mouse over the item, the subclass may set a ToolTip object for itself with code like:</p> <pre><code>ToolTip tip = new ToolTip() { Content = "Tooltip display value" }; ToolTipService.SetToolTip(this, tip); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload