WPF TreeView - How to scroll so expanded branch is visible

前端 未结 6 1798
孤城傲影
孤城傲影 2020-12-14 16:56

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 cr

6条回答
  •  醉酒成梦
    2020-12-14 17:41

    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.

    
     
       
     
    
    
    
    private void TreeViewSelectedItemChanged(object sender, RoutedEventArgs e)
    {
        TreeViewItem item = sender as TreeViewItem;
        if (item != null)
        {
            item.BringIntoView();
            e.Handled = true;  
        }
    }
    

提交回复
热议问题