This article is currently in the process of being translated into Spanish (~22% done).
If you are fluent in Spanish, then please help us - just point to any untranslated element inside the article and click the translation button to get started. Or have a look at the current translation status for the Spanish language.
If you see a translation that you think looks wrong, then please consult the original article to make sure and then use the vote button to let us know about it.
Please help us by translating the following metadata for the article/chapter, if they are not already translated.
If you are not satisfied with the translation of a specific metadata item, you may vote it down - when it reaches a certain negative threshold, it will be removed. Please only submit an altered translation of a metadata item if you have good reasons to do so!
La función de TreeView Control (vista de árbol), te permite mostrar en pantalla datos de jerarquías, en donde cada pieza de datos es representada por un nodo en el árbol. Cada nodo puede tener hijos y cada hijo puede tener otro hijo y así sucesivamente. Si alguna vez has usado el buscador de windows, entonces sabrás como se ve una vista de árbol - es el menú que muestra el folder actual en la estructura de tu equipo en la parte izquierda de "mi equipo" o "mi PC".
TreeView in WPF vs. WinForms
If you have previously worked with the TreeView control in WinForms, you might think of the TreeView control as one that's easy to use but hard to customize. In WPF it's a little bit the other way around, at least for newbies: It feels a bit complicated to get started with, but it's a LOT easier to customize. Just like most other WPF controls, the TreeView is almost lookless once you start, but it can be styled almost endlessly without much effort.
Just like with the ListView control, the TreeView control does have its own item type, the TreeViewItem, which you can use to populate the TreeView. If you come from the WinForms world, you will likely start by generating TreeViewItem's and adding them to the Items property, and this is indeed possible. But since this is WPF, the preferred way is to bind the TreeView to a hierarchical data structure and then use an appropriate template to render the content.
We'll show you how to do it both ways, and while the good, old WinForms inspired way might seem like the easy choice at first, you should definitely give the WPF way a try - in the long run, it offers more flexibility and will fit in better with the rest of the WPF code you write.
The WPF TreeView is indeed a complex control. In the first example, which we'll get into already in the next chapter, it might seem simple, but once you dig deeper, you'll see the complexity. Fortunately, the WPF TreeView control rewards you with great usability and flexibility. To show you all of them, we have dedicated an entire category to all the TreeView articles. Click on to the next one to get started.