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

How to expand the tree downto selected node in ViewModel

1 Answer 217 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Luka
Top achievements
Rank 1
Luka asked on 05 Apr 2013, 11:18 AM
I have this situation! I have a MVVM application and the code for the tree:
<telerik:RadTreeView
    IsExpandOnSingleClickEnabled="True"
    ItemsSource="{Binding DLYReasons, Mode=TwoWay}"
    SelectedItem ="{Binding SelectedTreeItem, Mode=TwoWay}">
    <telerik:RadTreeView.ItemContainerStyle>
        <Style TargetType="{x:Type telerik:RadTreeViewItem}">
            <Setter Property="FontWeight" Value="Normal" />
        </Style>
    </telerik:RadTreeView.ItemContainerStyle>
 
    <telerik:RadTreeView.ItemTemplate>
        <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>
            </StackPanel>
        </HierarchicalDataTemplate>
    </telerik:RadTreeView.ItemTemplate>
</telerik:RadTreeView>


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

Luka 

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 10 Apr 2013, 08:11 AM
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.

Tags
TreeView
Asked by
Luka
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or