Edit this page

IsExpandedBinding and IsExpandableBinding

Since Q1 2013 release, RadTreeListView has two new properties - IsExpandedBinding and IsExpandableBinding which can be used to synchronize its expanded and expandable states with your view-model.

cation Binding to the IsExpanded property of TreeListViewRow is not fully supported. You can consider using IsExpandedBinding property instead.

Use of IsExpandedBinding

IsExpandedBinding property can be used to show you whether a TreeListView's row is expanded or not.

Follow these steps to accomplish the task:

  1. For the purpose of this tutorial we will add a boolean property - IsExpanded to our WarehouseItem collection:

    Please, note that our WarehouseItem class implements the INotifyPropertyChanged interface.

    C#

    public class WarehouseItem : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    
        private bool isExpanded;
        private string name;
        private int count;
    
        public WarehouseItem(string name, int count, bool isExpanded = true)
        {
            this.Name = name;
            this.IsExpanded = isExpanded;           
        }
    
        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                if (value != this.name)
                {
                    this.name = value;
                    this.OnPropertyChanged("Name");
                }
            }
        }
    
        public bool IsExpanded
        {
            get
            {
                return this.isExpanded;
            }
            set
            {
                if (value != this.isExpanded)
                {
                    this.isExpanded = value;
                    this.OnPropertyChanged("IsExpanded");
                }
            }
        }
    protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, args);
            }
        }
    
        private void OnPropertyChanged(string propertyName)
        {
            this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
        }
    

    VB.NET

    Public Class WarehouseItem
        Implements INotifyPropertyChanged
        Public Event PropertyChanged As PropertyChangedEventHandler
    
        Private m_isExpanded As Boolean
        Private m_name As String
        Private count As Integer
    
        Public Sub New(name As String, count As Integer, Optional isExpanded As Boolean = True)
            Me.Name = name
            Me.IsExpanded = isExpanded
        End Sub
    
        Public Property Name() As String
            Get
                Return Me.m_name
            End Get
            Set(value As String)
                If value <> Me.m_name Then
                    Me.m_name = value
                    Me.OnPropertyChanged("Name")
                End If
            End Set
        End Property
    
        Public Property IsExpanded() As Boolean
            Get
                Return Me.m_isExpanded
            End Get
            Set(value As Boolean)
                If value <> Me.m_isExpanded Then
                    Me.m_isExpanded = value
                    Me.OnPropertyChanged("IsExpanded")
                End If
            End Set
        End Property
        Protected Overridable Sub OnPropertyChanged(args As PropertyChangedEventArgs)
            Dim handler As PropertyChangedEventHandler = Me.PropertyChanged
            RaiseEvent handler(Me, args)
        End Sub
    
        Private Sub OnPropertyChanged(propertyName As String)
            Me.OnPropertyChanged(New PropertyChangedEventArgs(propertyName))
        End Sub
    End Class
    
  2. Add RadTreeListView as demonstrated below:

    XAML

    <telerik:RadTreeListView x:Name="radTreeListView"
                                 IsExpandedBinding="{Binding IsExpanded, Mode=TwoWay}"
                                 AutoGenerateColumns="False">
            <telerik:RadTreeListView.ChildTableDefinitions>
                <telerik:TreeListViewTableDefinition ItemsSource="{Binding Items}" />
            </telerik:RadTreeListView.ChildTableDefinitions>
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"
                                    Header="Name" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding IsExpanded}" 
                                    Header="Is Expanded" />
            </telerik:RadTreeListView.Columns>
        </telerik:RadTreeListView>
    
  3. Here is a snapshot of the result:

Rad Tree List View radtreelistview how-to-isexpanded 01png

A complete example of using RadTreeListView's IsExpandedBinding property is available in the TreeListView's IsExpanded demo.

Use of IsExpandableBinding

The use of IsExpandableBinding would be similar as shown for the IsExpandedBinding.

A complete example of using RadTreeListView's IsExpandedBinding property is available in the TreeListView's OnDemandDataLoading demo.