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

Automatic scrolling for TreeView when node is expanded

1 Answer 722 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Harish
Top achievements
Rank 1
Veteran
Harish asked on 23 Jul 2020, 11:13 AM

Hi,

I am seeing that the wpf TreeView do not scroll automatically to show the expanded nodes, when I expand a node in the tree view(I have to scroll manually after expanding), So I want to achieve the behaviour in the gif that I attached. This was the default behaviour for my legacy winforms tree, but the wpf telerik:RadTreeView does not have that behaviour. How can I achieve that behaviour with wpf telerik:TreeView.

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 28 Jul 2020, 07:09 AM

Hi Harish,

You can achieve the desired result by handling the Expanded event of the control in the following manner:

        private void myTreeView_Expanded(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            var item = e.OriginalSource as RadTreeViewItem;
            var lastItem = item.Items[item.Items.Count - 1] as BusinessItem;
            Dispatcher.BeginInvoke(new Action(() =>
            {
                myTreeView.BringPathIntoView(lastItem.GetPath());
            }));
        }w
I've also attached a small sample project to demonstrate this implementation.

Please have a look and let me know if a similar approach would work for you.

Regards,
Dilyan Traykov
Progress Telerik

Tags
TreeView
Asked by
Harish
Top achievements
Rank 1
Veteran
Answers by
Dilyan Traykov
Telerik team
Share this question
or