1 回答
TA贡献1828条经验 获得超4个赞
在ListView的资源中设置以下样式:
<ListView.Resources>
<Style TargetType="ListViewItem">
<EventSetter Event="MouseEnter" Handler="ListViewItem_MouseEnter" />
<EventSetter Event="MouseLeave" Handler="ListViewItem_MouseLeave" />
</Style>
</ListView.Resources>
在后面的代码中,使用以下代码来确定当前悬停的项目。
private ListViewItem _currentItem = null;
private void ListViewItem_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
var item = sender as ListViewItem;
if (!Equals(_currentItem, item))
{
_currentItem = item;
// code to update window
}
}
private void ListViewItem_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
_currentItem = null;
}
- 1 回答
- 0 关注
- 356 浏览
添加回答
举报