How to expand RadTreeView using MVVM approach?

2 posts, 1 answers
  1. Yaroslav
    Yaroslav avatar
    153 posts
    Member since:
    Jan 2016

    Posted 02 Sep 2016 Link to this post

    Hello. I write WPF MVVM Prism 6 multimodule application. In some View (let us call it PeppyView) I have RadTreeView which bound to ObservableCollection located in PeppyViewModel. This radTreeView is populated with data from this ObservableCollection. In turn, the ObservableCollection is populated with data from binary *.DAT file when user is clicking on the 'Deserialize' RadButton. After populating with the data my RadTreeView is shown as collapsed RadTreeView. But I need that my RadTreeView is shown as expanded after its populating with data. Because ViewModel has to have no knowlage about the View in MVVM I can't call RadTreeView.ExpandAll method from ViewModel code. So how can I expand RadTreeView in my case? Is there a way to map UI control's method to ViewModule and call it there?
  2. Answer
    Martin Ivanov
    Martin Ivanov avatar
    1402 posts

    Posted 05 Sep 2016 Link to this post

    Hello Yaroslav,

    In order to achieve your requirement you can use an implicit style targeting RadTreeViewItem and use it to set the IsExpanded property of all items to True. 
        <Style TargetType="telerik:RadTreeViewItem">
            <Setter Property="IsExpanded" Value="True" />
    Or bind the IsExpanded property to a property from the items view models and set it while creating them.
        <Style TargetType="telerik:RadTreeViewItem">
            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
    You can find those approaches described in the Expanding and Collapsing Items help article.

    I hope this helps.

    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top