Reputation: 396
If i open a TreeView Item
which Header
is longer than the control, the scrollbar automatically jumps to the end of this item, which can be very disturbing...
Any workaround so that the scrollbar dont jump "automatically"?
Upvotes: 1
Views: 240
Reputation: 943
Well, you can handling the ScrollChanged event from ScrollViewer inside your TreeView.
So, you can write these lines of code here:
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);
Upvotes: 0
Reputation: 169320
You could try to handle the RequestBringIntoView
of the TreeViewItem
containers:
<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;
But please remember to always provide a Minimal, Complete, and Verifiable example of your issue when asking a question.
Upvotes: 3