How to expand RadTreeView using MVVM approach?

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

    Posted 02 Sep 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
    Admin
    Martin avatar
    1101 posts

    Posted 05 Sep 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. 
    <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.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top