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

Bring item into view without knowing their path

1 Answer 93 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Hiroshi
Top achievements
Rank 1
Hiroshi asked on 02 May 2014, 05:41 AM
Hello,

I'm working on a framework that is supposed to provide improvements to WPF controls. This framework also provides features for Telerik controls.

I would like to make a behavior that bring an item of a TreeView into view when it is (programmatically) selected.
The problem is, on the layer I'm working on, I have no idea of the path of the object to bring into the view (Because I don't know the associated view model). Basically I have the following method to implement in the behavior:

protected override void BringIntoView(object dataItem)
{
    // TODO: bring dataItem into the view of the AssociatedObject treeview
}


All I know is that dataItem is an item of the treeview. It can be collapsed and have no associated TreeViewItem yet. As far as I understand, under this situation I have to use the BringPathIntoView.

It is not a problem if I have to iterate through the whole graph of items, but I have to find the path of the item that was passed to this method. I can get the value of the TextSearch.TextPathProperty attached to the tree view, which can help me to construct the path of each item.

But how can I iterate through the children of a given item, since the children collection is defined by the HierarchicalDataTemplate used by the TreeViewItem that might be unrealized?

Thanks

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 02 May 2014, 03:50 PM
Hi Hiroshi,

As you noticed in order to create an container for a RadTreeViewItems those items should be realized. Until then you cannot iterate trough them.

As for your method - the item parameter is of type object which means that you won't have any information about it and therefore the creating of the path will be very difficult. It may be possible to find the properties that you need through reflection and traverse the tree afterwards but I don't believe this is the best solution. At this point in order to use the GetItemByPath method you can create the path in your view models. You can also take a look at the Bring Into View blog post and SDK example.

Regards,
Martin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
TreeView
Asked by
Hiroshi
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or