Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double Click a ListBox item to open a browser

I have a ListBox in my wpf window that binds to an ObervableCollection. I want to open the browser if someone clicks on an element of the ListBox (just like a link). Can someone tell me how to do this? I found something with listboxviews, does it only work this way or is there a way by just using the ListBox?

Yours

Sebastian

like image 771
Sebastian Müller Avatar asked May 04 '09 19:05

Sebastian Müller


1 Answers

You can add a style to ListBox.ItemContainerStyle, and add an EventSetter there:

<ListBox>     ....     <ListBox.ItemContainerStyle>         <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">             <EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_MouseDoubleClick"/>         </Style>     </ListBox.ItemContainerStyle> </ListBox> 

ListBoxItem_MouseDoubleClick is a method in your code behind with the correct signature for MouseDoubleClick.

like image 182
Bob King Avatar answered Sep 28 '22 16:09

Bob King