我正在使用一个类如下:
Class DirectoryViewItem
Property Namee As String
Property Iconn As BitmapImage
Property Path As String
Property SubNodes As New List(Of DirectoryViewItem)
End Class
我使用的xaml是:
<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>
代码工作正常,现在我想通过代码扩展 3 或一些 x 节点,我找到了使用这样的解决方案:
CType(DirectoryTreeView.Items(3), TreeViewItem).ExpandSubtree()
我发现CType
这里不是TreeViewItem
,但它是我的DirectoryViewItem
类型,......这怎么能做到?