WPF Treeview禁止水平滚动条自动滚动
程序员文章站
2022-06-08 22:14:30
...
Wpf的treeview,当item超过treeview的范围时,当点击这个item,会把这个item移到treeview的最左边或滚动条滚动至最上方。
需要在treeviewitem的style里加eventsetter
<TreeView>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<EventSetter Event="RequestBringIntoView" Handler="TreeViewItem_RequestBringIntoView"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
后台代码
private void TreeViewItem_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
e.Handled = true;
}
下一篇: WPF中ListBox滚动条自动滚动