Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the item doubleclick event of listview

What do I need to do in order to reference the double click event for a listview control?

like image 593
Sauron Avatar asked May 30 '09 06:05

Sauron


2 Answers

<ListView.ItemContainerStyle>     <Style TargetType="ListViewItem">         <EventSetter Event="MouseDoubleClick" Handler="listViewItem_MouseDoubleClick" />     </Style> </ListView.ItemContainerStyle> 

The only difficulty then is if you are interested in the underlying object the listviewitem maps to e.g.

private void listViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e) {     ListViewItem item = sender as ListViewItem;     object obj = item.Content; } 
like image 85
Oliver Avatar answered Sep 18 '22 23:09

Oliver


I'm using something like this to only trigger on ListViewItem double-click and not for example when you double-click on the header of the ListView.

private void ListView_MouseDoubleClick(object sender, MouseButtonEventArgs e) {     DependencyObject obj = (DependencyObject)e.OriginalSource;      while (obj != null && obj != myListView)     {         if (obj.GetType() == typeof(ListViewItem))         {             // Do something here             MessageBox.Show("A ListViewItem was double clicked!");              break;         }         obj = VisualTreeHelper.GetParent(obj);     } } 
like image 34
Oskar Avatar answered Sep 21 '22 23:09

Oskar