Expandir dinámicamente la vista de árbol

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?

preguntado el 24 de agosto de 12 a las 22:08

1 Respuestas

  1. Use el TreeView.ItemContainerStyle atar IsExpanded to a property on your items.
  2. Implementar ExpandSubtree on your items (all it needs to do is set that bound property on your items to true recursivamente).

Respondido 24 ago 12, 22:08

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

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.