答案 0 :(得分:2)
您可以尝试处理RequestBringIntoView
容器的TreeViewItem
:
<TreeView>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<EventSetter Event="RequestBringIntoView" Handler="OnRequestBringIntoView"/>
</Style>
</TreeView.ItemContainerStyle>
...
</TreeView>
private void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e) => e.Handled = true;
但请记住在提问时始终提供a Minimal, Complete, and Verifiable example您的问题。
答案 1 :(得分:0)
好吧,您可以从 TreeView 中的 ScrollViewer 处理 ScrollChanged 事件。
所以,你可以在这里写下这些代码:
var element1 = VisualTreeHelper.GetChild(sender as TreeView, 0) as X;
// Where X is the object inside your TreeView. Eg. StackPanel, Border...
var scrollviewer = VisualTreeHelper.GetChild(element1, 0) as ScrollViewer;
//Goes to the beggining of your content
scrollviewer.ScrollToLeftEnd();
// Another way is...
scrollViewer.ScrollToHorizontalOffset(e.HorizontalOffset + e.ExtentHeightChange);