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>
然后处理函数是
namespace EventHelper
{
public partial class ItemRequestBringIntoView
{
private void Item_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
e.Handled = true;
}
}
}
如果是在资源字典内新增RequestBringIntoView事件,则需要添加x:Class
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
x:Class="EventHelper.ItemRequestBringIntoView" >
</ResourceDictionary>
---------------------
原文: