What do I need to do in order to reference the double click event for a listview control?
<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; }
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); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With