TreeViewItem::ExpandSubtree Method ()
.NET Framework (current version)
Expands the TreeViewItem control and all its child TreeViewItem elements.
Assembly: PresentationFramework (in PresentationFramework.dll)
The following examples show how to find the selected TreeViewItem and expand it and all of it child items. The following XAML creates a TreeView and populates it with some data.
<StackPanel> <StackPanel.Resources> <XmlDataProvider x:Key="myCompany" XPath="Company/Employee"> <x:XData> <Company xmlns=""> <Employee Name="Don Hall"> <Employee Name="Alice Ciccu"> <Employee Name="David Pelton"> <Employee Name="Vivian Atlas"/> </Employee> <Employee Name="Jeff Price"> <Employee Name="Kari Hensien"/> </Employee> <Employee Name="Andy Jacobs"/> </Employee> <Employee Name="Bill Malone"> <Employee Name="Maurice Taylor"> <Employee Name="Sunil Uppal"> <Employee Name="Qiang Wang"/> </Employee> </Employee> </Employee> </Employee> </Company> </x:XData> </XmlDataProvider> <!-- Bind the HierarchicalDataTemplate.ItemsSource property to the employees under each Employee element. --> <HierarchicalDataTemplate x:Key="EmployeeTemplate" ItemsSource="{Binding XPath=Employee}"> <TextBlock Text="{Binding XPath=@Name}"/> </HierarchicalDataTemplate> </StackPanel.Resources> <TreeView Name="treeView1" ItemsSource="{Binding Source={StaticResource myCompany}}" ItemTemplate="{StaticResource EmployeeTemplate}"/> <Button Name="expandSelect" Margin="5,0,0,0" Content="Expand _Selected Item" Click="expandSelected_Click"/> </StackPanel>
The following code traverses the TreeView to find the selected TreeViewItem and then calls ExpandSubtree to display all child items of the selected TreeViewItem.
Note |
|---|
The GetTreeViewItem method only works for TreeViewItem controls that are not virtualized. To learn how to find a TreeViewItem that may be virtualized, see How to: Find a TreeViewItem in a TreeView. |
.NET Framework
Available since 4.0
Available since 4.0
Show:
