防止在 TreeView 中自动水平滚动 [英] Prevent Automatic Horizontal Scroll in TreeView

查看:34
本文介绍了防止在 TreeView 中自动水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当在我的树视图中选择一个节点时,它都会自动水平滚动到该项目.有没有办法禁用它?

Whenever a node is selected in my treeview, it automatically does a horizontal scroll to that item. Is there a way to disable this?

推荐答案

处理RequestBringIntoView 事件并将 Handled 设置为 true,框架不会尝试将该项目显示在视图中.例如,在您的 XAML 中执行以下操作:

Handle the RequestBringIntoView event and set Handled to true, and the framework won't try to bring the item into view. For example, do something like this in your XAML:

<TreeView>
    <TreeView.ItemContainerStyle>
        <Style TargetType="TreeViewItem">
            <EventSetter Event="RequestBringIntoView" Handler="TreeViewItem_RequestBringIntoView"/>
        </Style>
    </TreeView.ItemContainerStyle>
</TreeView>

然后在你的代码隐藏中:

And then this in your code-behind:

private void TreeViewItem_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
    e.Handled = true;
}

这篇关于防止在 TreeView 中自动水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆