Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > TreeView > BringIntoViewMode fails to work as expected

Not answered BringIntoViewMode fails to work as expected

Feed from this thread
  • Roland Vonk avatar

    Posted on Feb 9, 2012 (permalink)

    We have set the BringIntoViewMode to HeaderAndItems for a particular case and the result is not what I expect. Am I doing something wrong or is there a problem with the TreeView?

    In an adapter (as we are building an MVVM application) we attach a handler to the ItemPrepared and LoadOnDemand events.

    Originally it seemed logical to simply do the following in the LoadOnDemand event handler:

    	var treeViewItem = (RadTreeViewItem) e.OriginalSource;
    
    	treeViewItem.BringIntoView();
    

    But of course should fail since technically the child nodes are not yet loaded.

    Than I tried adding the following code to the ItemPrepared event handler:

    	e.PreparedItem.BringIntoView();

    This of course brings each child node into view as they are being "prepared", so that is also not the desired result. So finally I ended up with:

    e.PreparedItem.ParentItem.BringIntoView();

    But again no "items" were brought into view (even though in the ItemPrepared event the above code is called for each child node prepared).

    Please let me know what I'm doing wrong!

    Regards,
    Roland

    Reply

  • Petar Mladenov Petar Mladenov admin's avatar

    Posted on Feb 14, 2012 (permalink)

    Hi Roland Vonk, 

    Invoking the BringIntoView() in the ItemPrepared event could be too early sometimes and it may need a Dispatcher(). However, the best solution in these cases is to use the BringPathIntoView() method which accepts a string path to the desired item and automatically expands and prepares containers on its way through the target item. We highly suggest you to try the BringPathIntoView method, starting with this blog post. Please let us know if you need further assistance on this. 

    Regards,
    Petar Mladenov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Roland Vonk avatar

    Posted on Feb 15, 2012 (permalink)

    Hello Petar,

    I cannot seem to get the Dispatcher possibility to work so I've attempted to isolate the "path" of a child element of the expanded node so that I can bring it into view.

    if (_associatedControl.SelectedContainer != null)
    {
    	var childrenCount = _associatedControl.SelectedContainer.Items.Count;
    	var scrollToItem = _associatedControl.ContainerFromItemRecursive(_associatedControl.SelectedContainer.Items[(childrenCount > 10) ? 10 : childrenCount - 1]);
    	var scrollToItemPath = scrollToItem.FullPath;
    	_associatedControl.BringPathIntoView(scrollToItem.FullPath);
    }

    The idea of course is that since there is limited space in the window with the tree, I don't want to scroll the parent completely out of view. So I've simply decided to try and scroll UP TO the first 10 possible elements.

    But it would appear that when I try to retrieve the scrollToItem RadTreeViewItem that children are still not loaded.

    At what point can I know for sure that the children are loaded?

    Regards,
    Roland

    Reply

  • Petar Mladenov Petar Mladenov admin's avatar

    Posted on Feb 16, 2012 (permalink)

    Hi Roland Vonk ,

     In order to be sure that a RadTreeViewItem has been already generated is to use the ItemPrepared event.
    Could you please give it a try and let us know if it helps you?

    Greetings,
    Petar Mladenov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Roland Vonk avatar

    Posted on Feb 16, 2012 (permalink)

    Hello Petar,

    Thanks for your recommendations, as this seems to work. I had tried using the ItemPrepared event before but to no avail. With your advice I also used another approach at isolating an element in the parent list. By executing "BringPathIntoView" for each loaded child element as they were loaded (UP TO a maximum e.PreparedItem.Index) I was able to achieve a desirable result.

    if (_radTreeView.SelectedContainer != null)
    {
    var itemIndex = e.PreparedItem.Index;
    var itemToBringIntoView = _radTreeView.SelectedContainer.Items[(itemIndex > 9) ? 9 : itemIndex];
    var itemContainer = _radTreeView.ContainerFromItemRecursive(itemToBringIntoView);
    var itemPath = itemContainer.FullPath;
    _radTreeView.BringPathIntoView(itemContainer.FullPath);
    }

    Its not ideal since BringPathIntoView will be executed for each child loaded, but it works.

    Regards,
    Roland

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > TreeView > BringIntoViewMode fails to work as expected
Related resources for "BringIntoViewMode fails to work as expected"

WPF TreeView Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]