Hello,
How can get/set the scroll property of a XamDataTree
I am refreshing it in code behind and i need to maintain the scroll position
Thanks in advanced
Hi,
XamDataTree is handling the scrolling by itself. So if you refresh it(basically assign new ItemsSource) it will be invalidated and all of the top level nodes will be collapsed. At this point the tree will look differently in height because of these difference in its state. So my point is that if you have stored the value of the vertical scrollbar it probably wont be valid because the scrollable hight eventually will be different.
Your best option here might be to store the first visible node before the refresh of the tree and after it to call ScrollNodeIntoView method and pass it that stored node.
Please let me know if I could be of further assistance on the matter.
hello,
Thanks for your response
how to know the first Node?
Hussein
Hi Hussein,
Sorry for the delayed response. Well it turned out that finding the top most item is not as trivial as I thought especially when you don't have an access to the internals of the XamDataTree.
Basically such a functionality(sync-ing the scroll position) is not built in the control and it appears that there is not an easy way to achieve it. I'm currently working on a solution/workaround. The direction I'm going is basically storing all expanded nodes so we could re-expand them after the DataSource is refreshed. The other thing is that finding and storing the top most visual node is not enough and we need to find the bottom most one as well.
I will get back to you tomorrow with sample solution.
I have already found a workaround and now it works
l_folder is the new tree collections
_tree.Insert(_tree.Count, l_folder);
_tree.RemoveAt(0);
Thanks
I'm glad to hear that you found a way around this. The DataTree does not do all the invalidations when changing the ItemsSource collection what is the case for setting a new collection as an ItemsSource.