Expanding and Collapsing Items
The RadTreeListView control allows you to control the state of its items both programmatically via its public methods and through the IsExpandedBinding and IsExpandableBinding properties.
Expand and Collapse Items Programmatically
There are four methods which you can use to programmatically control the state of the items:
- ExpandHierarchyItem(object hierarchyItem): Expands the respective GridViewRow for the given item.
- CollapseHierarchyItem(object hierarchyItem): Collapses the respective GridViewRow for the given item.
- ExpandAllHierarchyItems(): Expands all hierarchy items.
- CollapseAllHierarchyItems(): Collapses all hierarchy items.
All four methods can also be given an additional boolean parameter (preserveLocalSettings) which determines if the IsExpandable state of the item set via the RowStyle or RowStyleSelector properties should be preserved.
Example 1: Expand the third item after the control is loaded
IsExpandedBinding and IsExpandableBinding
The RadTreeListView also exposes the IsExpandedBinding and IsExpandableBinding properties which you can use to synchronize its expanded and expandable states with your viewmodel.
Binding to the IsExpanded property of TreeListViewRow is not fully supported and that is why we recommend using the IsExpandedBinding property instead.
IsExpandedBinding
IsExpandedBinding property can be used to control whether a row is expanded or not.
First start by adding a boolean property to your business items as demonstrated in Example 1. For the purposes of this article, we will extend the WarehouseItem class from the Getting Started article.
Example 2: Extend the WarehouseItem class
Note that the class inherits from the ViewModelBase class which implements the INotifyPropertyChanged interface.
Then define the RadTreeListView control as demonstrated in Example 2.
Example 3: Declare RadTreeListView in XAML
With this setup expanding or collapsing a row will result in the respective checkbox from the IsExpanded column to be updated.
A complete example of using RadTreeListView's IsExpandedBinding property is available in the TreeListView's IsExpanded demo.
IsExpandableBinding
The use of IsExpandableBinding is identical to that of the IsExpandedBinding - you need to define a boolean property in your business class and bind it to the IsExpandableBinding property of the RadTreeListView control.
A complete example of using RadTreeListView's IsExpandableBinding property is available in the TreeListView's OnDemandDataLoading demo.