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

item offset position

3 Answers 225 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
robert
Top achievements
Rank 1
robert asked on 02 Oct 2012, 07:03 AM
hello, how can i get the item offset position. I want to search a item with getitembypath and
scroll the item to the middel of the treeview with the vertical offset function. How can i do this?
thank you ...

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 02 Oct 2012, 11:15 AM
Hello Robert,

 If you need to scroll to the item you've got by the GetItemByPath, you better use the BringPathintoViewMethod() which performs these two tasks:
1) Generates the containers needed along the path to the given item
2) Brings the item into view (expanding and scrolling to the item).
Please check out the following help article and let us know how it goes.

Regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
robert
Top achievements
Rank 1
answered on 02 Oct 2012, 12:25 PM
Thank you for your help. When i use BringPathIntoView the node is expanded and shown as last entry (vertical) of the treeview window. I want that the item is shown in the middle of the treeview window (when enough notes behind are available) not on last position, i. e. verticaloffset node position + 500. How can i do this?
Please see attached screenshots.
Thank you ...
0
Petar Mladenov
Telerik team
answered on 05 Oct 2012, 07:42 AM
Hi Robert,

 When the item in question has  children , you can set the RadtreeView's property BringIntoViewModel to "HeaderAndItems";

<telerik:RadTreeView x:Name="treeView"  PathSeparator="|" BringIntoViewMode="HeaderAndItems">
which will scroll so that the child items of the brought item will be visible.
When it has no children , you have to perform this scrolling on your own, and this is not so easy, because you need to wait for the Bring operation to finish. You can try with Dispatcher like so:
private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        this.treeView.BringPathIntoView("Item 2|Item 2.1|Item 2.1.3");
        RadTreeViewItem container = this.treeView.GetItemByPath("Item 2|Item 2.1|Item 2.1.3");
        container.IsSelected = true;
        Dispatcher.BeginInvoke(new Action(()=>
        {
            this.treeView.ScrollViewer.ScrollToVerticalOffset(this.treeView.ScrollViewer.VerticalOffset + this.treeView.ScrollViewer.ViewportHeight/2);
        }), DispatcherPriority.ApplicationIdle);
    }
This is also demonstrated in the attached project.

Greetings,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TreeView
Asked by
robert
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
robert
Top achievements
Rank 1
Share this question
or