TreeviewItem IsExpanded and LoadOnDemand

2 posts, 0 answers
  1. luc
    luc avatar
    24 posts
    Member since:
    Aug 2011

    Posted 17 Dec 2014 Link to this post


    I use a treeview with LoadOnDemand enabled. When I expand a node it seems that the property IsExpanded switch from False to True (normal) + switch from True to False (i dont understand) and finally from False to True. We can imagine that final status is the goal, BUT when i expand an empty node the final switch (False to True) dont occurs (think its link with observablecollection)
    I join a sample here post. If you open the Root node + open Item node and then try to open empty node SubItem you will see that SubItem IsExpanded property stay false.
    What's the issue ?
  2. Petar Mladenov
    Petar Mladenov avatar
    3139 posts

    Posted 22 Dec 2014 Link to this post

    Hi Luc,

    The RadTreeViewItem has internal coercing logic which checks whether the item to be expanded has any children:
    protected internal virtual void OnIsExpandedChanged(bool oldValue, bool newValue)
    (this.Items.Count == 0)
                    this.IsExpanded = false;
    RadTreeView gives you the ability to expand an item manually by clicking the expander button of the RadTreeViewItem because the IsLoadOnDemandEnabled is set to True. This also gives you the option to add child items on this expand. There are two possible results with such scenario:
    -- you expand such item and do not add children (this is what happens in your project on expanding sub item). The result is - the treeview sets IsEsxpanded to true, then it coerces the value back to false because there are no children ( the code from the snippet above kicks in). The expander button is collapsed.
    -- you expand such item and set children, for example:
    else if (it.Name.StartsWith("SubItem"))
                      it.Items.Add(new Item());
    The RadTreeViewItem stays with IsExpanded True and the Expander button is shown as expanded.

    Our advice for you is to set IsLoadOnDemandEnabled on RadTreeViewItem level (you can do it via style) and this way you can have expander button only for the items that will receive children from your code.

    Petar Mladenov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top