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
I Used Expression SDK 4.0
Jaimir G.
You can add a style to ListBox.ItemContainerStyle, and add an EventSetter there:
ListBoxItem_MouseDoubleClick is a method in your code behind with the correct signature for MouseDoubleClick.
I have updated AndrewS solution in order to solve the issue with firing executing the command if double click anywhere in the list box:
And in the XAML the declaration for the ListBox is:
I wanted to solve this without needing to handle the listBoxItem double click event in the code-behind, and I didn't want to have to override the listBoxItem style (or define the style to override in the first place). I wanted to just fire a command when the listBox was doubleclicked.
I created an attached property like so (the code is very specific, but you can generalise it as required):
}
I then declare my ListBox with the attached property and my target command:
Hope this helps.