How to expand the tree downto selected node in ViewModel

2 posts, 0 answers
  1. Luka
    Luka avatar
    7 posts
    Member since:
    Mar 2013

    Posted 05 Apr 2013 Link to this post

    I have this situation! I have a MVVM application and the code for the tree:
        ItemsSource="{Binding DLYReasons, Mode=TwoWay}"
        SelectedItem ="{Binding SelectedTreeItem, Mode=TwoWay}">
            <Style TargetType="{x:Type telerik:RadTreeViewItem}">
                <Setter Property="FontWeight" Value="Normal" />
            <HierarchicalDataTemplate ItemsSource="{Binding ChildElements}">
                <StackPanel Orientation="Horizontal">
                    <Border MaxHeight="20" MaxWidth="20" MinHeight="20" MinWidth="20"
                            Background="{Binding ImageResourceId, Converter={StaticResource valueToStaticResource}, ConverterParameter={StaticResource StaticResourceValuesTreeShape}}"/>
                    <Label Content="{Binding ReasonCode}"></Label>

    When I refresh the tree I want to select the previous item and expand it downto the level where this item resides.

  2. Pavel R. Pavlov
    Pavel R. Pavlov avatar
    1237 posts

    Posted 10 Apr 2013 Link to this post

    Hello Luka,

    In your scenario you can use the BringPathIntoView() method. Basically, each RadTreeViewItem should hold a reference to its parent. By doing so you will be able to create a path to a desired item. Furthermore, you can store this path before refreshing the control. This approach is further described in this article and this blog post. Also, in the blog post you can find and download a runnable project demonstrating this approach.

    Please take a look at it and let us know if it works for you.

    All the best,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top