This is a migrated thread and some comments may be shown as answers.

IsExpandedBinding not working as expected

3 Answers 233 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Stéphane
Top achievements
Rank 1
Stéphane asked on 04 Feb 2014, 04:59 PM
Hello,

I made a sample MVVM project where I have a ViewModel for my nodes:
public class WarehouseItem : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
 
        private bool isExpanded;
        private string name;
        private IList<WarehouseItem> m_items;
 
        public WarehouseItem(string name, int count, bool isExpanded = true)
        {
            this.Name = name;
            this.IsExpanded = isExpanded;
            this.Items = (from l_i in System.Linq.Enumerable.Range(0, count)
                          select new WarehouseItem("SubItem" + (l_i + 1), 0, false)).ToList();
        }
 
        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");
                }
            }
        }
 
        public IList<WarehouseItem> Items
        {
            get { return this.m_items; }
            set
            {
                if (this.m_items != value)
                {
                    this.m_items = value;
                    this.OnPropertyChanged("Items");
                }
            }
        }
 
        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));
        }
    }


I have bound the IsExpanded property to a property of my ViewModel like this:
<telerik:RadTreeListView IsExpandedBinding="{Binding IsExpanded, Mode=TwoWay}"
                         AutoGenerateColumns="False" ItemsSource="{Binding}">
    <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>

And I was a little bit disappointed when I saw that if you add a node with a ViewModel where the IsExpanded property is already set to True, the node will be first collapsed than expanded.
If you have a lot of nodes and you refresh the state of the nodes frequently, it's really annoying.

Best regards,

3 Answers, 1 is accepted

Sort by
0
Yordanka
Telerik team
answered on 06 Feb 2014, 04:30 PM
Hello Stéphane,

Thank you for the feedback.

Actually, this is expected - the data is loaded and the binding is executed a little bit later. That's why expanding seems like that.

Regards,
Yordanka
Telerik

Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

0
Arthur
Top achievements
Rank 1
answered on 24 Jun 2016, 03:53 PM

Hi,

This behavior is really annoying. I have some commands like move row up/down, drag drop and even load where all the layout is jumping arround because the rows are inserted in collapsed state and expanded afterwards.

Is it an option to write a behavior with an attached property of type bool, bind the expanded state of my view model to that property and react on property change to set row.IsExpanded to that value immediately?

I do not need a Dispatcher.BeginInvoke inbetween.

0
Dilyan Traykov
Telerik team
answered on 28 Jun 2016, 02:26 PM
Hello Arthur,

I'm afraid that as my colleague already mentioned, this behavior is expected and cannot be bypassed.

Regards,
Dilyan Traykov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
TreeListView
Asked by
Stéphane
Top achievements
Rank 1
Answers by
Yordanka
Telerik team
Arthur
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or