Expandir dinámicamente la vista de árbol
Frecuentes
Visto 6,142 veces
1
I am using a class as follows:
Class DirectoryViewItem
Property Namee As String
Property Iconn As BitmapImage
Property Path As String
Property SubNodes As New List(Of DirectoryViewItem)
End Class
and the xaml I used is:
<TreeView Name="DirectoryTreeView"
TreeViewItem.Expanded="DirectoryTreeView_Expanded"
Grid.Row="0">
<TreeView.ItemTemplate >
<HierarchicalDataTemplate ItemsSource="{Binding SubNodes}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Iconn}"
Width="32" Height="32"
VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBlock Text="{Binding Namee}"
VerticalAlignment="Center" HorizontalAlignment="Left" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
The code is working fine, now I want to expand the 3 or some x node through code, and I found the solution to use something like this:
CType(DirectoryTreeView.Items(3), TreeViewItem).ExpandSubtree()
Encontré que el CType
here is not TreeViewItem
but it is my DirectoryViewItem
type, ... how can this be done?
1 Respuestas
4
- Use el
TreeView.ItemContainerStyle
atarIsExpanded
to a property on your items. - Implementar
ExpandSubtree
on your items (all it needs to do is set that bound property on your items totrue
recursivamente).
Respondido 24 ago 12, 22:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas wpf vb.net treeview expand treeviewitem or haz tu propia pregunta.
Could you please tell me in more detail, I am bit new to advanced stuff - surpavan
@surpavan: It's not advanced, really. See esta publicación para un ejemplo. - media pensión
That worked and I did this before seeing your link. Hehe. Thanks for the time and for sharing the information is the best way to understand. Many thanks. - surpavan