This question is locked. New answers and comments are not allowed.
Hello,
we're evaluating the RadTreeView in order to replace the Silverlight Toolkit TreeView. The Reason is that we have trees where nodes can have >1000 children and we need Virtualization.
One Feature in our application is a search inside the tree. We do this in our ViewModel by exposing a Property "SelectedItem" and bind this to the TreeView via TwoWay binding. The ViewModel sets the SeletedItem - Property, so it's selected in the tree:
Selection works fine but the tree does not expand and scroll to the selected item. I've tried to derive a TreeView from RadTreeView, override the OnSelectionChanged() and bring the selected item into the view there. Problem is due to virtualization that the TreeViewItems are not generated when they're not visible, so ContainerFromItemRecursive() does not work and many other attempts also:
BringPathIntoView() works with a hardcoded Path but now the problem is: How to get the Path of the selected item?
When searching your forum, I've found another approach using ContainerBinding described here:
http://www.telerik.com/help/silverlight/radtreeview-how-to-bind-hierarchical-data-use-containerbindingcollection.html
But this approach would force us to put UI or user control specific properties into our ViewModels which is not an option, Also the objects could live in two different trees on the same view so we would have to introduce "IsSelected" and "IsExpanded" properties for tree 1 and another property set for tree 2, otherwise selection in tree 1 would cause side effects on tree 2.
Can anybody help me to find a solution for this?
Thanks in advcance,
Bernd
we're evaluating the RadTreeView in order to replace the Silverlight Toolkit TreeView. The Reason is that we have trees where nodes can have >1000 children and we need Virtualization.
One Feature in our application is a search inside the tree. We do this in our ViewModel by exposing a Property "SelectedItem" and bind this to the TreeView via TwoWay binding. The ViewModel sets the SeletedItem - Property, so it's selected in the tree:
<telerik:RadTreeView IsVirtualizing="True" ItemsSource="{Binding Portfolios}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" BringIntoViewMode="HeaderAndItems" telerik:TextSearch.TextPath="Name"> <telerik:RadTreeView.ItemTemplate> <telerik:HierarchicalDataTemplate ItemsSource="{Binding Portfolios}">... </telerik:HierarchicalDataTemplate> </telerik:RadTreeView.ItemTemplate></telerik:RadTreeView>private void JumpInTree(object obj){ var item = mySearchList.GetNextSearchItem(...) as BaseViewModel; if (item != null) SelectedItem = item;}Selection works fine but the tree does not expand and scroll to the selected item. I've tried to derive a TreeView from RadTreeView, override the OnSelectionChanged() and bring the selected item into the view there. Problem is due to virtualization that the TreeViewItems are not generated when they're not visible, so ContainerFromItemRecursive() does not work and many other attempts also:
public class BindableTreeViewNew : RadTreeView{ protected override void OnSelectionChanged(Telerik.Windows.Controls.SelectionChangedEventArgs e) { base.OnSelectionChanged(e); // the correct selected Item var item = SelectedItem; // can't rely on this var selectedContainer = SelectedContainer; // does not work because item was not visible yet: var selectedContainer2 = ContainerFromItemRecursive(SelectedItem); // this works but how to get the path of SelectedItem? BringPathIntoView(@"Root\XYZ\ABC"); }}BringPathIntoView() works with a hardcoded Path but now the problem is: How to get the Path of the selected item?
When searching your forum, I've found another approach using ContainerBinding described here:
http://www.telerik.com/help/silverlight/radtreeview-how-to-bind-hierarchical-data-use-containerbindingcollection.html
But this approach would force us to put UI or user control specific properties into our ViewModels which is not an option, Also the objects could live in two different trees on the same view so we would have to introduce "IsSelected" and "IsExpanded" properties for tree 1 and another property set for tree 2, otherwise selection in tree 1 would cause side effects on tree 2.
Can anybody help me to find a solution for this?
Thanks in advcance,
Bernd
