WPF TreeView 悬停时突出显示行 [英] WPF TreeView Highlight Row On Hover

查看:36
本文介绍了WPF TreeView 悬停时突出显示行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,将鼠标悬停在 TreeView 中的标题上会突出显示标题.我想将鼠标悬停在 TreeView 中行的任何部分以突出显示整行(就像 Windows 资源管理器一样).有人可以提供一个如何做到这一点的例子吗?

Currently, hovering over a header in the TreeView will highlight the header. I would like hovering over any part of the row in the TreeView to highlight the entire row (much like windows explorer does). Could someone provide an example of how to do that?

推荐答案

您需要将 TreeViewItemControlTemplate 更改为实际上是控件的整个宽度.

You need to change the ControlTemplate for the TreeViewItem to actually be the entire width of the control.

这里有关于这个问题的讨论以及解决方案:

There is a discussion about this issue, along with a solution, here:

http://leecampbell.blogspot.com/2009/01/horizo​​ntal-stretch-on-treeviewitems.html

这里还有一个冗长的答案,没有讨论:

There's another lengthy answer here, without the discussion:

http:///social.msdn.microsoft.com/Forums/en-US/wpf/thread/b04f73e2-0b10-4d97-a6da-64df2e30c21d/

所以我的意思是将这些示例作为指南.如果您采用与上面第二个链接(来自 MSDN 论坛)中完全相同的代码并添加以下代码:

So I meant those examples to be guides. If you take exactly the same code as is in the second link above (from MSDN forums) and just add this:

<Trigger Property="IsMouseOver" Value="True">
    <Setter Property="Background" TargetName="Bd"
            Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
</Trigger>

ControlTemplate 你会看到你在鼠标悬停时获得了高亮颜色.显然你需要调整颜色等等,但这就是你需要做的——修改 TreeViewItemControlTemplate 使其占据整个宽度并为 IsMouseOver 添加一个 Trigger.

to the ControlTemplate you'll see that you get the highlight color on mouseover. Obviously you'll need to tweak the color and whatnot, but that's what you'll need to do - modify the ControlTemplate of the TreeViewItem so that it takes up the entire width and add a Trigger for IsMouseOver.

这篇关于WPF TreeView 悬停时突出显示行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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