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

How to expand RadTreeView using MVVM approach?

1 Answer 334 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Dmitry
Top achievements
Rank 1
Dmitry asked on 02 Sep 2016, 07:14 AM
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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 05 Sep 2016, 12:55 PM
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. 
<Window.Resources>
    <Style TargetType="telerik:RadTreeViewItem">
        <Setter Property="IsExpanded" Value="True" />
    </Style>
</Window.Resources>
Or bind the IsExpanded property to a property from the items view models and set it while creating them.
<Window.Resources>
    <Style TargetType="telerik:RadTreeViewItem">
        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
    </Style>
</Window.Resources>
You can find those approaches described in the Expanding and Collapsing Items help article.

I hope this helps.

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
TreeView
Asked by
Dmitry
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or