When I expand items in my treeview so that scrolling is necessary, a scrollbar appears. However, it doesn't scroll down for the newly expanded branch of items - they get cropped by the bottom of the control. So as I continue expanding items at the bottom of the tree, I have to keep manually scrolling down to see the new children. Anyone have a suggestion for how make it automatically scroll to show the newly expanded items?
You can use a simple EventSetter in TreeViewItem style to invoke an event handler when the item is selected. Then call BringIntoView for the item.
<TreeView > <TreeView.ItemContainerStyle> <Style TargetType="{x:Type TreeViewItem}"> <EventSetter Event="Selected" Handler="TreeViewSelectedItemChanged" /> </Style> </TreeView.ItemContainerStyle> </TreeView> private void TreeViewSelectedItemChanged(object sender, RoutedEventArgs e) { TreeViewItem item = sender as TreeViewItem; if (item != null) { item.BringIntoView(); e.Handled = true; } }
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