In my WPF application, I need to highlight the ListViewItem whenever something is about to fall on it. I override OnDragEnter, OnDragOver, OnDragLeave, etc. ListViewItem to apply my styles (say background changes). It is working fine. but after removing somthing in the listview element, when I click the list elements, the selection and mouse effects are not working properly. How can i solve this?
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);
}
}
source
share