views:

21

answers:

2

I want to catch the event when a listview is left-clicked on an empty space - i.e. clicking on no item within the listview control.

I've search in the Events list of the listview but found none. How can I do this? Please help!

[Edit] What I want to do if I could catch this event: Deselect all items in the listview.

+1  A: 

ListBoxItem control handles clicks on ListBox. You should either:

  • use PreviewMouseDown event on ListBox
  • Add event handler in code via myListBox.AddHandler method

See How to Attach to MouseDown Event on ListBox for explanation and code examples.

zendar
+1  A: 

If you attach a handler to the MouseLeftButtonDown event on the ListView it will only fire when areas outside of a ListViewItem are clicked. Any clicks inside the items will be handled by the items themselves to drive the ListView's selection behavior.

You can make changes to the clickable areas by adjusting the Background ({x:Null} is not clickable, anything else is) and Margin of the ListViewItems by setting an ItemContainerStyle on the ListView. Also make sure that you are not using a null Background on the ListView itself (White is the default, Transparent works too).

John Bowen