IsExpandedBinding not working as expected

4 posts, 0 answers
  1. Stéphane
    Stéphane avatar
    3 posts
    Member since:
    Apr 2012

    Posted 04 Feb 2014 Link to this post

    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,
  2. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 06 Feb 2014 Link to this post

    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).

  3. UI for WPF is Visual Studio 2017 Ready
  4. Arthur
    Arthur avatar
    2 posts
    Member since:
    Oct 2015

    Posted 24 Jun Link to this post

    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.

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 28 Jun Link to this post

    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.
Back to Top