当鼠标移动时突出显示 WPF DataGrid 上的列
我希望当鼠标移动时突出显示 WPF 数据网格上的列。我面临的一些问题是:
- 获取列的坐标,以在鼠标悬停在列上时进行测试
- 更改列的背景颜色
任何帮助将不胜感激。
I wish to highlight the columns on a WPF datagrid as the mouse moves. Some of the problems I face are:
- Getting the coordinates of columns to test for when the mouse is over them
- Changing the background color of a column
Any help will be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何更新 DataGridCell 的样式并在其中定义“IsMouseOver”触发器?像这样的东西:
编辑:
下面是一个解决方案:1) 突出显示当前悬停的单元格,2) 突出显示整行,3) 突出显示整列。我只是快速编写了此代码,尚未对其进行彻底测试,因此您可能会遇到一些问题。但无论如何,这应该能让您了解如何完成这些任务。
我的突出显示整个列的解决方案涉及使用两个附加属性,当鼠标悬停在 DataGridCell 上时,这些属性被分配给 DataGridCell。只需检查一下,看看它是否适合您。
XAML:
DataGridBehavior 类:
How about updating the style for the DataGridCell and defining an "IsMouseOver" trigger in it? Something like this:
EDIT:
Below is a solution that: 1) highlights the currently hovered cell, 2) highlights the entire row, and 3) highlights the entire column. I just coded this up quickly and haven't tested it thoroughly so you might encounter some issues. But anyway, this should give you an idea on how they can be done.
My solution for highlighting the entire column involves the use of two attached properties that were being assigned to the DataGridCell when the mouse is over it. Just check it out and see if it works for you.
XAML:
DataGridBehavior class: