在我的WPF应用程序中,每当有东西要掉落到ListViewItem上时,我需要对其进行突出显示。我重写了ListViewItem的OnDragEnter、OnDragOver、OnDragLeave等方法来应用我的样式(比如改变背景)。这个功能很好用。但是,在将某些东西放在一个ListView项上之后,当我点击该项时,选择和鼠标悬停效果就不能正常工作了。我该怎么解决这个问题?
public class CustomListViewItem : ListViewItem
{
protected override void OnDragOver(System.Windows.DragEventArgs e)
{
this.Background = Brushes.Green;
base.OnDragOver(e);
}
protected override void OnDragEnter(System.Windows.DragEventArgs e)
{
this.Background = Brushes.Green;
base.OnDragEnter(e);
}
protected override void OnDragLeave(System.Windows.DragEventArgs e)
{
if (!this.IsSelected)
{
this.Background = Brushes.Transparent;
this.BorderBrush = Brushes.Transparent;
}
base.OnDragLeave(e);
}
}