I'm trying to write a custom WPF/MVVM TreeView control that will automatically scroll (as many as possible) of the child items into view when a parent item is expanded.
I've found this post, WPF TreeView - How to scroll so expanded branch is visible, but it seems that only works when the tree items actually descend from TreeViewItem.
My Tree Item class is just a plain C# object - along the lines of Josh Smith's blog http://www.codeproject.com/Articles/26288/Simplifying-the-WPF-TreeView-by-Using-the-ViewMode, which are lazy loaded in the IsExpanded property setter in the Tree Item class.
Stepping into the OnExpand event handler, I can see that the original source is a TreeViewItem (created by the framework behind the scenes) which has my tree item object in the header field. This TreeViewItem has only 1 visual child, a grid, which in turn has 3 visual children, ToggleButton, Border and ItemsPresenter.
Does anyone have a hint as to how I can get the corresponding visual components for my child items, on which I can then call BringIntoView()?
Found a very nice behavior which scrolls the selected item into view, located here:
This unfortunately doesnt cater for when the item is expanded, but can be modifed according to your exact requirements. If you need any help just let me know.
http://www.codeproject.com/Articles/28959/Introduction-to-Attached-Behaviors-in-WPF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With